Instantly share code, notes, and snippets.

Embed
What would you like to do?
shell script for adb wifi
#!/bin/bash
#Modify this with your IP range
MY_IP_RANGE="192\.168\.1"
#You usually wouldn't have to modify this
PORT_BASE=5555
#List the devices on the screen for your viewing pleasure
adb devices
echo
#Find USB devices only (no emulators, genymotion or connected devices
declare -a deviceArray=(`adb devices -l | grep -v emulator | grep -v vbox | grep -v "${MY_IP_RANGE}" | grep " device " | awk '{print $1}'`)
echo "found ${#deviceArray[@]} device(s)"
echo
for index in ${!deviceArray[*]}
do
echo "finding IP address for device ${deviceArray[index]}"
IP_ADDRESS=$(adb -s ${deviceArray[index]} shell ifconfig wlan0 | awk '{print $3}')
echo "IP address found : $IP_ADDRESS "
echo "Connecting..."
adb -s ${deviceArray[index]} tcpip $(($PORT_BASE + $index))
adb -s ${deviceArray[index]} connect "$IP_ADDRESS:$(($PORT_BASE + $index))"
echo
echo
done
adb devices -l
#exit
@flyingzl

This comment has been minimized.

flyingzl commented Jan 12, 2015

very cool. You can also install the app named "adb wireless", it's more easy and useful, and can be used out of box.

@jamescfli

This comment has been minimized.

jamescfli commented Jul 31, 2015

This does not work for Moto G either.

The last two lines of the output show unauthorized:

...
List of devices attached 
192.168.6.110:5555     unauthorized
@jxllh123456

This comment has been minimized.

jxllh123456 commented Sep 13, 2016

finding IP address for device 47Q6R16328002931
IP address found : 172.18.214.94
Connecting...

@jxllh123456

This comment has been minimized.

jxllh123456 commented Sep 13, 2016

right ?

@meicuihui

This comment has been minimized.

meicuihui commented Jun 24, 2017

good

@akidee

This comment has been minimized.

akidee commented Aug 18, 2017

I updated your script to consider netcfg, ifconfig and currently connected ports: https://gist.github.com/akidee/04ade213c92f087b06920698190f71b5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment