Auto logon to web-authenticated wireless

At my current workplace I am using a guest wireless network.  After connecting, I need to open any web page and I am redirected to the login page and need to enter my provided username and password.  After submitting, I can browse any page and use the connection for email and other tasks.

Whilst this is only a minor inconvenience, it is definitely a candidate for automation.

A single line wget command is all we really need.  I have wrapped it up into a shell script below:



wget -O /dev/null --no-check-certificate --post-data "username=$username&password=$password&buttonClicked=4&err_flag=0&"

-O /dev/null throws any downloaded content away, --no-check-certificate is fairly self-explanatory (wget wouldn’t connect to the https address without this), --post-data wraps up the various name/value pairs that the login form is expecting.

For most of these login forms, you only need a username and password, but I found with this one it also needed a few extra parameters.

So, the next step is to get this script to run automatically after connecting to the wireless network.  On Ubuntu (or any Debian based distro), there is a directory structure under /etc/network that includes an if-up.d directory.  Any scripts in here will be run after a network interface is brought online.  These scripts don’t have access to the SSID (as far as I know), but this can be obtained with the following command:

iwgetid --raw

Wrapping it all together, we can put the following script in the “if-up.d” directory:



if [  "`iwgetid --raw`" = "$ssid" ]
wget -O /dev/null --no-check-certificate  --post-data "username=$username&password=$password&buttonClicked=4&err_flag=0&"

Remember to change the values of username, password and ssid.  Set the URL to the forms action value and add remove parameters as necessary.  Also, another point I learned the hard way is that the script can’t have a “.sh” extension, so name it “something” not “” (and remember to chmod +x it).

If you need to then connect to a VPN, this can also be added to the script.

Leave a Reply