Home » Android » ADB Commands » Connect adb shell over Wireless / Wifi / Ethernet / TCP network

Connect adb shell over Wireless / Wifi / Ethernet / TCP network

NOTE: for below article, replace IP address whereever required with your IP address

If you want to connect your mobile/device over wifi adb and access the shell, by default most of the mobiles will not be able to connect, but if you are actively working with some development platform, it might have adb working properly over network, in both of the scenarios, use below mentioned commands to connect adb over network.

If you are using a android development environment device or a rooted device which allows to do certain experiments, in those adb might be already enabled over network,

1. Check the IP address of the device, for this, make sure you have your device connected to network, then goto Settings -> Network & Internet -> click on connected network interface ( Wifi/Ethernet ) -> Select Again -> This will show the device IP address.

OR you can connect device over USB cable and type,

 $ adb shell 
 $ ifconfig 

Note the IP address and then exit from USB adb and remove USB cable. Now, connect over network using IP address as,

$ adb connect
connected to 
 $ adb shell 

Sometimes, you may seen an error as below,

$ adb connect
unable to connect to

For this, we need to restart the TCP port using USB adb as, connect device over USB cable and type

$ adb tcpip 5555
restarting in TCP mode port: 5555

Now, you will be able to connect over network as,

$ adb connect
connected to 

If you have not removed the USB cable, you might seen the same device as two devices as,

$ adb devices
List of devices attached
B2NGAA8831702707	device	device
$ adb -s shell
B2N_sprout:/ $

You can also automate this adb connection over network to your device using a bash script as below, this script will wait till your android device is connected to network and then only it will attempt to connect over adb.

$ vim adb_connect.sh
# sudo apt install fping



sudo adb kill-server

itest=$(fping $DEVICE_IP | grep alive)
while [ \"$itest\" == \"\" ] 
        echo "device not online yet.. wait for 1 sec.."
        sleep 1
        itest=$(fping $DEVICE_IP | grep alive)
echo "$DEVICE_IP is now online"

sudo adb connect $DEVICE_IP
sleep 3

adb -s "$DEVICE_IP:$ADB_PORT" shell

In the above script, you need to change DEVICE_IP to your android device’s IP address. If you are connecting to different devices over same network, you can also use the provision of passing last digit of ip address by enabling DEVICE_IP=192.168.1.$IP_LAST_DIGIT and by passing IP last digit from command line to the script.

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment