How to intercept captive portal URL via powershell?

523 views Asked by At

When connecting to a walled-garden network (e.g. free airport wifi), the network usually automatically opens the URL to its captive portal in the browser. How would one intercept this URL with Powershell?

Background: I use DNScrypt-Proxy to encrypt my DNS traffic, but it often breaks captive portal requests. I'm writing a Powershell script to detect when my computer is trying to connect to a walled-garden network and temporarily disable DNScrypt-proxy to allow the portal request through. I'd actually like to open the Captive Portal URL in a non-default browser window, and to do this programmatically, I'd need to be able to intercept* the URL that the network tries to open. (*It's not 100% necessary that the URL doesn't go through to my default browser, as I can always close the browser tab. It would just be cleaner if it doesn't.)

I suspect this involves packet-sniffing, but I'm really not familiar at all with network-related stuff. Simple solutions, especially those that don't require any external programs like Wireshark, are preferable. Thanks!

EDIT: I've found this code that doesn't intercept the request (I don't know what means a captive network even uses to tell the default browser to open the URL, so I don't even know where to start investigating it), but supposedly it fetches the URLs of currently open tabs, which would suffice. It didn't work when I tried it, though, and I have no idea why. (Note: I'm running Firefox on Windows 10.)

$ShellWindows = (New-Object -ComObject Shell.Application).Windows()
($shellwindows | ? {$_.locationurl -like "http*"}).locationURL
0

There are 0 answers