Skip to content

Instantly share code, notes, and snippets.

@tompi
Created February 11, 2020 09:05
Show Gist options
  • Save tompi/8cd8dc501a45ca39757866994d55cae1 to your computer and use it in GitHub Desktop.
Save tompi/8cd8dc501a45ca39757866994d55cae1 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Script to setup wifi debugging on first connected device,
# find the ip address and then connect to it
#
# Author: Thomas.Haukland@gmail.com
#
PORT="5555"
DEVICE=`adb devices | grep -v "^List" | grep -v "^$" | sed "s/[[:space:]]*device//" | head -1`
if [ -z "$DEVICE" ]
then
echo "No connected devices found...";
exit -1;
fi
echo "Found device $DEVICE."
echo "Finding ip address"
IP=$(adb -s $DEVICE shell ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk "{print \$2;}" | sed "s/addr://")
if [ -z "$IP" ]
then
echo "IP address not found :(";
exit -1;
fi
echo "Found $IP."
echo "Setting up $DEVICE for wifi debug on port $PORT"
adb -s $DEVICE tcpip $PORT
echo "Connecting... Remember your machine needs to be connected to the same wifi for this to work"
adb connect $IP:$PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment