2

When I connect to a WiFi hotspot with a captive portal or HTML login interface, I find that I need to guess the portal's IP address, generally running through this list:

  1. 192.168.0.1
  2. 192.168.1.1
  3. 10.0.0.1
  4. 10.0.1.1
  5. ... etc

It's guess-work, and tedious. Is there a tool for Linux that automatically detects and takes me to the correct address so I can enter my starbucks receipt's WiFi code?

1 Answer 1

2

There may well be a smarter way to do this but if you have a list of the candidate IP addresses you could easily put together a python script that uses requests to try to get a web page from each in turn, possibly looking for likely text in each, and then use webbrowser.open( ) to open your browser to the correct one.

Something like:

#! usr/bin python3

import sys
from urllib.request import urlopen
from urllib import error
import webbrowser

def try_ip(ip_address: str) -> bool:
    """ Try to get a web page from the IP address."""
    try:
        resp = urlopen(f"http://{ip_address}/", None, timeout=1)
    except error.URLError:
        return False
    resp.close()
    return resp.code == 200

IP_LIST = [
    "192.168.0.1", "192.168.1.1",
    # etc
   ]

def main():
   """ The main loop """
   for ip in IP_LIST:
      if try_ip(ip):
          webbrowser.open(f"http://{ip}/")
          sys.exit()

   sys.exit("None of the usual IPs worked")

if __name__ == "__main__":
    main()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.