Skip to content

Instantly share code, notes, and snippets.

@teocci
Last active May 5, 2023 13:22
Show Gist options
  • Save teocci/62d7f4ecc4204a641d52b7e27d7591b3 to your computer and use it in GitHub Desktop.
Save teocci/62d7f4ecc4204a641d52b7e27d7591b3 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Created by teocci.
#
# @author teocci@yandex.com on 2017-Nov-14
#
# Test an IP address for validity:
# Usage:
# valid_ip IP_ADDRESS
# if [[ $? -eq 0 ]]; then echo good; else echo bad; fi
# OR
# if valid_ip IP_ADDRESS; then echo good; else echo bad; fi
#
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do
address=$(adb -s $SERIAL shell ip addr show wlan0 | grep 'inet ' | cut -d' ' -f6|cut -d/ -f1)
foo=$(adb -s $SERIAL shell ip addr show wlan0 | grep 'inet ' | cut -d' ' -f6|cut -d/ -f1 | cut -d . -f 4)
port="7$(printf "%03d" $foo)"
id="${SERIAL%%:*}"
if ! valid_ip $id; then
printf "Connecting to %s\n" "$SERIAL"
adb -s $SERIAL tcpip $port
adb -s $SERIAL connect $address:$port
fi
done
adb devices
#!/bin/bash
#
# Created by teocci.
#
# @author teocci@yandex.com on 2017-Nov-14
#
# Test an IP address for validity:
# Usage:
# valid_ip IP_ADDRESS
# if [[ $? -eq 0 ]]; then echo good; else echo bad; fi
# OR
# if valid_ip IP_ADDRESS; then echo good; else echo bad; fi
#
APK=$1
if [ ! -f `which adb` ]; then
echo 'You need to install the Android SDK before running this script.';
exit;
fi
if [ ! $APK ]; then
echo 'Please provide an .apk file to install.'
else
for d in `adb devices | ack -o '^\S+\t'`; do
adb -s $d install $APK;
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment