[TUTORIAL] Autologin script for Hotspots - Captive Portals

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Wed Aug 23, 2017 16:37    Post subject: [TUTORIAL] Autologin script for Hotspots - Captive Portals Reply with quote
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.




_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
Sponsor
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Sun Aug 27, 2017 21:56    Post subject: Reply with quote
Random username changer bug fixed:

Updated script:
Quote:

#!/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
#########################################################

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"

UNREACHEABLE=1;


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 &

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
sjocolaatje
DD-WRT Novice


Joined: 26 Feb 2024
Posts: 1

PostPosted: Mon Feb 26, 2024 9:08    Post subject: Reply with quote
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:

Code:
curl -d "auth_user= xxxxxxxxxxx" -d "auth_pass= xxxxxxxxxxx" -d "accept=OK" http://your_hotspot_login_url/login


Thanks, hopefully this is useful to someone.
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Sat Mar 02, 2024 15:02    Post subject: Reply with quote
sjocolaatje wrote:
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:

Code:
curl -d "auth_user= xxxxxxxxxxx" -d "auth_pass= xxxxxxxxxxx" -d "accept=OK" http://your_hotspot_login_url/login


Thanks, hopefully this is useful to someone.


Thanks for sharing sjocolaatje. Good to know it is still working for someone Smile

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum