Skip to content

Instantly share code, notes, and snippets.

@barriosnahuel
Last active July 25, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barriosnahuel/bd8aa6966ff9e7e2b1ce3be0b2d87dcb to your computer and use it in GitHub Desktop.
Save barriosnahuel/bd8aa6966ff9e7e2b1ce3be0b2d87dcb to your computer and use it in GitHub Desktop.
Command line alias to connect ADB to one device to work on Wi-Fi
#!/bin/bash
########
## USAGE
########
#
# > ac
#
########
## SETUP
########
#
# Add an alias like the following one:
# > alias ac='sh ~/Downloads/android-device-connect.sh'
SAVEIFS=$IFS
IFS=$'\n'
clear
echo +———————————————————————————————————————————————————+
echo ANDROID IP CONNECT
echo +———————————————————————————————————————————————————+
devices_array=( $(adb devices) )
devices=()
echo -\> Select Device
for (( i = 1 ; i < ${#devices_array[@]} ; i++ )) do
echo \[$i\] ${devices_array[$i]} | sed s/[[:space:]]device//g
j=$((i-1))
a=( $(echo ${devices_array[$i]} | sed s/[[:space:]]device//g) )
devices[$j]=$a
done
#if devices_array.length == 1 ==> autoselect.
# // Select option
#######read option #Uncomment for full command
option=1
device=${devices[$((option-1))]}
###echo $device
###echo "adb -s $device shell ifconfig wlan0 | awk '/inet addr/ {gsub("addr:", "", $2); print $2}"
ip=( $(adb -s $device shell ifconfig wlan0 | awk '/inet addr/ {gsub("addr:", "", $2); print $2}'))
###echo $ip
#echo -\> Port? #Uncomment for full command
#read Port #Uncomment for full command
port=5555
# use tcpip
echo "adb -s $device tcpip $port";
adb -s $device tcpip $port
# connect to
echo "adb -s $device connect $ip:$port";
adb -s $device connect $ip:$port
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment