Home > Enterprise >  Run command on Android phone from PC
Run command on Android phone from PC

Time:03-25

I am using tethering on an Andorid phone to share the internet connection to my PC. Sometimes I need to get a new IP address, for that I switch to airplane mode, then disable it and I get a new IP. I am looking for a way to do this trick from my pc. So I need to run a single command on my phone from my PC, and I have absolutely no idea on how to do it, and if i need to root my android device.

Thank you !

CodePudding user response:

Using ADB (no root required)

// Open Wifi settings screen
adb shell am start -a android.settings.WIRELESS_SETTINGS

// Call key down event
adb shell input keyevent 20

// Call key click event to turn off wifi
adb shell input keyevent 23

// Key click again to turn on wifi
adb shell input keyevent 23

// Get the ip address
adb shell ip route

Using SVC (root required)

// Disable Wifi
adb shell su -c 'svc wifi disable'

// Enable Wifi
adb shell su -c 'svc wifi enable'

// Get the ip address
adb shell ip route
  • Related