Created
March 23, 2021 10:32
-
-
Save Amareis/a39e0fa39260a7d23abb7908fc295226 to your computer and use it in GitHub Desktop.
Simple bash script to switch connected Android phone to wi-fi adb mode and optionally forward port from computer to phone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if ! command -v adb &> /dev/null | |
then | |
echo "adb is not globally installed, using android sdk version" | |
#you can just set your path to android platform tools | |
export PATH="$PATH:~/Android/Sdk/platform-tools" | |
fi | |
adb disconnect | |
adb usb | |
sleep 1 | |
echo "Wait for USB device..." | |
adb wait-for-usb-device | |
adb devices | |
IP=$(adb shell ip route | cut -d' ' -f9) | |
echo "IP: $IP" | |
echo "Switch to tcpip" | |
adb tcpip 5555 | |
echo "Connecting..." | |
while true; do | |
res=$(adb connect $IP | cut -d' ' -f1) | |
[[ "$res" == "connected" ]] && break | |
sleep 1 | |
done | |
echo "Connected!" | |
PORT=$1 | |
if [ -n "$PORT" ] | |
then | |
echo "Forward port $PORT" | |
sleep 2 | |
adb -e reverse tcp:$PORT tcp:$PORT | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment