Skip to content

Instantly share code, notes, and snippets.

@axemorgan
Last active September 22, 2015 17:00
Show Gist options
  • Save axemorgan/ffa95bf0f53df09897b7 to your computer and use it in GitHub Desktop.
Save axemorgan/ffa95bf0f53df09897b7 to your computer and use it in GitHub Desktop.
A shell script to read the IP adress of a USB connected Android device and automatically re-connect to it via wireless ADB.
# A command line utility for automatically connecting ADB (Android Debug Bridge) to a USB connected Android device
# Records the status of the wifi interface on the device
adb shell ifconfig wlan0 > line
if [ "$?" -gt 0 ]
then
echo "Couldn't read IP address from device. Is it connected via USB?"
exit 1
fi
# Parses the IP address from the status
IP_ADDRESS=$(awk '{ print $3 }' line)
if [ "$IP_ADDRESS" == "assign" ]
then
echo "Couldn't access wireless interface. Is the device connected to wifi?"
rm line
exit 2
fi
rm line
#Restart ADB in wireless mode
adb tcpip 5555
echo $IP_ADDRESS
#ADB won't connect wirelessly if there is a USB device attached
read -p 'Disconnect your device and press [Enter] to re-connect wirelessly.'
#Connect to the device using the parsed IP address
adb connect $IP_ADDRESS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment