Skip to content

Instantly share code, notes, and snippets.

@mohamad-supangat
Last active February 7, 2022 02:38
Show Gist options
  • Save mohamad-supangat/dc7347609bffdf115dac119e84165455 to your computer and use it in GitHub Desktop.
Save mohamad-supangat/dc7347609bffdf115dac119e84165455 to your computer and use it in GitHub Desktop.
Android auto connect to wifi from shell
#!/system/bin/sh
# i use https://github.com/steinwurf/adb-join-wifi for auto connect to wifi
# tanks
# wait for boot to finish completely
while [[ `getprop sys.boot_completed` -ne 1 ]]
do
sleep 1
done
# sleep an additional 2m to ensure init is finished
sleep 120
# always run at background
while true
do
# check internet connection first
if ping -q -c 1 -w 1 google.com >/dev/null; then
echo "network connect => `date`" > /sdcard/wifi_connection_test.log
else
# start to connecting to wifi
WIFI_STATUS=$(dumpsys wifi | grep "mNetworkInfo")
SSID='Ukurdanuji'
if [[ "$WIFI_STATUS" != *"$SSID"* ]]; then
am start -n com.steinwurf.adbjoinwifi/.MainActivity -e ssid $SSID
fi
# send data login to mikrotik login page
curl -XPOST -s -d 'username=jvm&password=sukses' 'http://10.5.50.1/login' > /sdcard/wifi_login_result.log
# uncheck if u using wget
# wget --post-data 'username=jvm&password=sukses' 'http://wifi.jvm/login' > /data/local/tmp/wifi.log
fi
sleep 400
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment