Skip to content

Instantly share code, notes, and snippets.

@kamleshkarwande
Last active April 24, 2023 21:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kamleshkarwande/fe3edd5d13757fcedd457ac4c0953a97 to your computer and use it in GitHub Desktop.
Save kamleshkarwande/fe3edd5d13757fcedd457ac4c0953a97 to your computer and use it in GitHub Desktop.
shell script to connect android devices over wifi.
#!/bin/bash
echo "This script works with ONLY one Android device connected to system !!!"
echo "Killing adb"
adb kill-server
sleep 2
PORT_NO=6969
CONNETED_DEVICES=$(adb devices | wc -l)
if [ "$CONNETED_DEVICES" -le 2 ]; then
echo "NO Android device connected to your machine via USB."
else
IPADDRESS=$(adb shell ip addr show wlan0 | grep "inet\s" | awk '{print $2}' | awk -F'/' '{print $1}')
if [ -z "$IPADDRESS" ]; then
read -p "NO IP Address found, please check in device setting and Enter ip address: " IPADDRESS
else
echo "device IP is $IPADDRESS, please allow debug on device."
fi
echo "IP ADDRESS : "$IPADDRESS
adb tcpip $PORT_NO
read -p "Disconnect the device and press enter:-"
sleep 2
RESP=$(adb connect $IPADDRESS:$PORT_NO)
echo $RESP
if [ "$RESP" == "connected to $IPADDRESS:$PORT_NO" ]; then
echo "ENJOY wireless debug :)"
else
echo "Something went wrong, Please try again."
fi
fi
@kamleshkarwande
Copy link
Author

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