Automatically log into a network with a captive portal in Windows?

13,784

Solution 1

I don't know about simple... I use a tool called webinject.pl in order to test web sites. It's a perl script that allows you to specify inputs and expected results and could easily be configured for this. It might take you an hour to make it work.

As for how to automate it. The Windows Task Scheduler is pretty robust and can trigger on a myriad of events. You could tie it to a logon event or event log entry, or simply have it run every 5 minutes (that's a bit painful). For instance, I get an event 32 in the system log when I establish a network connection. That might do it.

Solution 2

You can use lynx (the version with SSL support) - a text based browser - with a cmd_args script file containing the commands needed to log in. You can generate such a script file by logging in to the wifi with lynx once and logging the input. Do this by calling lynx with the following argument:

lynx.exe -cmd_log=%USERPROFILE%\lynxlog.txt`

Then you can rename that file and use it by calling lynx as follows:

lynx.exe -cmd_script=FILENAME_HERE

Put this in a batch file. (Either use the full path to the lynx executable or set that path in the PATH environment variable.)

Once you get that working, make a scheduled task triggered by event id 10000 in source NetworkProfile of log Microsoft-Windows-NetworkProfile/Operational which calls it:

Task Scheduler trigger example

Personally, I bundle that with iexpress.exe to run it hidden in the background and make sure the scheduled task is set to run even if I'm not logged on. I just set this up on my computer a few weeks ago and it's been working great!

Source: My article on How to Automate Captive Portal Login.

Solution 3

I've done this in the past with Windows task scheduler and a php+mysqllite script. The php+mysqllite script just checked to see if it could reach google, if it got redirected, it checked to see if it had a routine for the domain it got redirected to, if so, it ran it. The mysqllite was to keep the cookies for the headless browser I implemented in php. It would probably be a lot less work to just use a greasemonkey equivalent to do the log-in. (with the down side being the browser would pop up and do things every time your scheduler gets tripped.)

The task scheduler trigger will vary from machine to machine. I had one laptop that would log wifi connections as events and they included the ssid so I could filter to only trigger on the ones I cared about.

On my current laptop, it seems the only event that reliably gets fired is the DHCP client connect. Of course, this fries every time I get an IP address and doesn't tell me an SSID.

You can check what events are available for you to trigger off of with the windows event viewer. I just turned on and off my wifi 3 times and checked what events were triggered 3 times in the last hour.

Share:
13,784
Clark Smalls
Author by

Clark Smalls

.NET Developer, Agile enthusiast, Martial Arts (Pakua) practitioner, 41, married, 4 kids and not enough free time to form this as a proper paragraph!

Updated on September 18, 2022

Comments

  • Clark Smalls
    Clark Smalls almost 2 years

    I have a Wi-Fi network at the office that requires logging in with a captive portal. It requires logging in with username and password.

    I would like to somehow run a script that automatically logs in as soon as I connect to the network, without having to start my browser and keep it open.

    Oddly enough, I managed to find such a client for Android, CoovaAX which is no longer available, but not one for Windows. I have Windows 7, if it matters.

    Does anybody have a simple solution for this? I'd rather not have to spend time to code my own tool for this.

  • Clark Smalls
    Clark Smalls about 12 years
    Thanks. I don't know if this solves my issue completely, I guess it could connect to the site and send my credentials, but I'd still need to automatically fire it up when I connect to the company's wifi network. Any idea how to do that? Could I catch an event with Scheduler, perhaps?
  • Cameron
    Cameron over 8 years
    @uSlackr Would you be able to provide the code you used for this?
  • uSlackr
    uSlackr over 8 years
    @Cameron Which code? The webinject.pl is available for download. the XML config file will be specific to your use case.
  • Cameron
    Cameron over 8 years
    Yeah could I see the XML as an example? Thanks