Created
March 20, 2020 20:11
-
-
Save jjv360/ee5e2e58c8262f8a485297855a656063 to your computer and use it in GitHub Desktop.
Start WiFi debugging an Android device.
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
#!/usr/bin/env bash | |
# | |
# Connect to android device for debugging over WiFi. Simply plug it in, run this | |
# script, then unplug it again. | |
# | |
# Find path to ADB | |
function adbpath() { | |
# List of possible locations | |
PossiblePath1="$HOME/Library/Android/sdk/platform-tools/adb" | |
PossiblePath2="$HOME/Library/Application Support/SideQuest/platform-tools/adb" | |
PossiblePath3="adb" | |
# Find one that exists | |
[[ -e "$PossiblePath1" ]] && echo "\"$PossiblePath1\"" && return | |
[[ -e "$PossiblePath2" ]] && echo "\"$PossiblePath2\"" && return | |
[[ -e "$PossiblePath3" ]] && echo "\"$PossiblePath3\"" && return | |
# Not found! | |
echo "Unable to find ADB!" | |
exit 1 | |
} | |
ADB=$(adbpath) | |
# Output header | |
echo "" | |
echo " +----------------------+" | |
echo " | ADB WiFi Debug |" | |
echo " +----------------------+" | |
echo " v1 " | |
echo "" | |
# Set ADB to USB mode | |
echo "> Setting ADB to USB mode..." | |
eval "$(adbpath) usb" > /dev/null 2>&1 | |
# Wait for user to connect their phone | |
echo "> Waiting for phone... (connect your phone via USB now)" | |
while true; do | |
# Check if device connected | |
Out=`eval "$ADB shell echo 'IsConnected'" 2>&1` | |
if [[ "$Out" == "IsConnected" ]]; then | |
break | |
fi | |
# Nope, wait a bit | |
sleep 1s | |
done | |
# Get device's IP | |
echo "> Fetching phone's IP address..." | |
IP=`eval "$ADB shell ip -f inet addr show wlan0" | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | head -1` | |
echo " Found IP: $IP" | |
# Set device to TCP mode | |
echo "> Setting TCP connect mode..." | |
eval "$(adbpath) tcpip 5555" | |
sleep 2s | |
eval "$(adbpath) connect $IP:5555" | |
# Out=`eval "$ADB connect $IP:5555" 2>&1` | |
# if [[ "A" =~ refused ]]; then | |
# echo "Failed, connection refused! Check that remote debugging is enabled on your phone." | |
# fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment