Search code examples
windowsnetwork-programmingwifi-directhotspotcaptiveportal

Is there a way to implement captive portal on windows hotspot?


I am looking for a way to implement a captive portal for the windows 10 - mobile hotspot. The idea is to redirect all devices that connect to the hotspot to a webpage.

I was able to find this article which shows how to do it in linux.

But I have been unsuccessful in finding a similar one for windows. Posts like this one proved to be dead ends.

I am okay with using a simple nginx server to give 302 redirect response to clients if needed, but prefer not to use any existing software that implements a captive portal.

UPDATE

I have succeeded in triggering a captive portal on clients (linux laptop, android device etc) using a workaround.

Whenever a device connects to the hotspot it sends a request to some predefined websites to check if the wifi connection has internet access. If it gets a 302 response it generates the captive portal window.

So I added the following entries to the hosts file on windows machine.

127.0.0.1 clients3.google.com  #android
127.0.0.1 connectivitycheck.gstatic.com  #android
127.0.0.1 nmcheck.gnome.org  #ubuntu

These requests will then be resolved locally using the hosts file entries and sent to the nginx server which gives a 302 redirect to all http requests.

enter image description here


Solution

  • The setup I mentioned in the UPDATE above was tweaked finally to get where I wanted. I used dnschef, an open-source dns server that works perfectly as a command line client. The steps followed.

    1. Start windows mobile hotspot.

    2. Go to Network adapters => Select hotspot adapter => Change IPv4 settings => set 127.0.0.1 as DNS server.

    3. Start dnschef with --fakeip = 192.168.137.1
    4. Start an http server on 192.168.137.1 and give 302 redirect response to all requests.

    And that's it! Whenever a device connects to the hotspot, it will attempt to connect to any one of the preset websites used to determine internet connectivity. These requests will be resolved locally by dnschef to our Nginx server. The Nginx server then gives a 302 redirect which triggers captive portal on the client.