Posted: Wed Aug 23, 2017 16:37 Post subject: [TUTORIAL] Autologin script for Hotspots - Captive Portals
Hello,
I had an issue about unattended login to Public Wi-Fi (Captive Portal) I have TP-Link WR1043ND Router. It doesn't support some wget commands and CURL doesn't exist. I made a solution with Raspberry Pi Zero Wireless. Raspberry is very cheap Linux computer smaller than your credit card. Please check the photos.
What I did. I bought Raspberry Pi Zero Wireless (about 30-40 dollars) RealVNC Server is working on this tiny computer. It powered by my router's USB port. I wrote following bash script. I added this script to Raspberry's crontab with this command:
Code:
sudo crontab -e
@reboot sh /home/rpi/Desktop/start.bash &
Create a file on your Desktop as start.bash:
Quote:
#!/bin/bash
# Hotspot AutoLogin Script for Raspberry and Linux Systems
# v1.0 - 23.08.2017
# Twitter: @mkaand
# For Support please visit DD-WRT forums
# https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=310780
#########################################################
rm -f /home/pi/Desktop/logs
sleep 60;
testserver="google.com."
ipaddsrc[0]="username=xxxxxxxxxxx&password=yyyyyyyyyyyyyy"
ipaddsrc[1]="username=xxxxxxxxxxx&password=yyyyyyyyyyyyyy"
ipaddsrc[2]="username=xxxxxxxxxxx&password=yyyyyyyyyyyyyy"
ipaddsrc[3]="username=xxxxxxxxxxx&password=yyyyyyyyyyyyyy"
rand=$[ $RANDOM % 4 ] #If you added x usernames above write x
UNREACHEABLE=1;
while [ $UNREACHEABLE -ne "0" ];
do
ping -q -c4 -W5 $testserver;
UNREACHEABLE=$?;
if [ $UNREACHEABLE -eq 0 ];then
echo "Internet is UP at `date`" >> /home/pi/Desktop/logs;
else
echo "Internet is DOWN at `date`" >> /home/pi/Desktop/logs;
curl -d "${ipaddsrc[$rand]}" -X POST http://your_hotspot_login_url/login
sleep 10;
fi
UNREACHEABLE=1;
sleep 60;
done
#sudo crontab -e
#@reboot sh /home/rpi/Desktop/start.bash &
Basically above code pings google.com every 60 sec. If connection down, It writes to logs "Internet is DOWN" with date and time and it choose randomly an username and password set and try to login via CURL. If the connection is UP it writes to logs. This loop never ends. I fix my problem with this way. I hope it helps for someone.
Note: You have to find out your captive portal's (Public Wifi) login-form inputs. Which inputs need to your login. You need to find out. Most of systems just needs username and password but name of input maybe difference. For Example for username: uname, user, username, id etc. You need to check and change my script.
#!/bin/bash
# Hotspot AutoLogin Script for Raspberry and Linux Systems
# v1.1 - 28.08.2017
# Twitter: @mkaand
# For Support please visit DD-WRT forums
# https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=310780
#########################################################
while [ $UNREACHEABLE -ne "0" ];
do
rand=$[ $RANDOM % 4 ] #If you added x usernames above write x
ping -q -c4 -W5 $testserver;
UNREACHEABLE=$?;
if [ $UNREACHEABLE -eq 0 ];then
echo "Internet is UP at `date`" >> /home/pi/Desktop/logs;
else
echo "Internet is DOWN at `date`" >> /home/pi/Desktop/logs;
curl -d "${ipaddsrc[$rand]}" -X POST http://your_hotspot_login_url/login
sleep 10;
fi
UNREACHEABLE=1;
sleep 60;
done
#sudo crontab -e
#@reboot sh /home/rpi/Desktop/start.bash &
This was a super useful post for me! Using this, I was finally able to solve the problem of not being able to automatically log into a captive portal when the connection has dropped. I would like to add though, that in my case I had to explicitly set the value of the submit button. I could not find anything online about this online, I just assumed that the curl command would submit my user name and password, but in my case the script did not work until I set the accept button to "OK", so took quite an effort to figure this out. In case anybody runs into the same problem, below is how I changed the curl command for my specific captive portal:
This was a super useful post for me! Using this, I was finally able to solve the problem of not being able to automatically log into a captive portal when the connection has dropped. I would like to add though, that in my case I had to explicitly set the value of the submit button. I could not find anything online about this online, I just assumed that the curl command would submit my user name and password, but in my case the script did not work until I set the accept button to "OK", so took quite an effort to figure this out. In case anybody runs into the same problem, below is how I changed the curl command for my specific captive portal: