For the initial settings of WiFi cerdentials and configuration on a standalone device (ESP32), I try to implement a captive portal using the CaptivePortal
example for ESP32 DNSServer
(see original source). I'm using Arduino IDE 1.8.13 and ESP32 core 1.0.4.
Different from the cited source, the example reads (as often seen in posts for that):
IPAddress apIP(192, 168, 1, 1);
This works well when connecting my laptop and opening firefox, which the tells me I'ld have to sign in by opening a signin-page.
This does not work with my android phone. It always tells me "no connection to internet".
In the latest version of the ESP core as cited above, the IP address is modified to
IPAddress apIP(8,8,4,4); // The default android DNS
This in fact works, even with android device.
I now tried different IP addresses (192.168.4.1
, 8.8.8.8
, 142.250.186.131
, which is connectivitycheck.gstatic.com
in real life, and some more). What did happen:
- Using an address out of the private pool (
192.168.x.y
) did lead to "No connection to the internet" - Using any of the public addresses did open the portal page.
I updated the DNSServer library to version 1.0.5 of the core, as that allowed for debugging the dns server. Additionally, I added some Serial prints for debugging. Using 192.168.1.1, the output reads:
dhcps: send_offer>>udp_sendto result 0
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 18 - AP_PROBEREQRECVED
DNS responds: 192.168.1.1 for epdg.epc.mnc002.mcc262.pub.3gppnetwork.org
DNS responds: 192.168.1.1 for north-america.pool.ntp.org
DNS responds: 192.168.1.1 for mtalk.google.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for alt4-mtalk.google.com
DNS responds: 192.168.1.1 for gstatic.com
DNS responds: 192.168.1.1 for android.googleapis.com
DNS responds: 192.168.1.1 for google.com
--- Begin http request ---
GET / HTTP/1.1
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M)
Host: 192.168.1.1
Connection: Keep-Alive
Accept-Encoding: gzip
--- End http request ---
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for android.clients.google.com
DNS responds: 192.168.1.1 for google.com
DNS responds: 192.168.1.1 for service.game-mode.net
DNS responds: 192.168.1.1 for play-lh.googleusercontent.com
DNS responds: 192.168.1.1 for play.googleapis.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for gld.push.samsungosp.com
DNS responds: 192.168.1.1 for googleapis.com
DNS responds: 192.168.1.1 for ssl.google-analytics.com
DNS responds: 192.168.1.1 for beacons.gvt2.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for google.com
DNS responds: 192.168.1.1 for yahoo.com
--- Begin http request ---
GET / HTTP/1.1
Connection: close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,en;q=0.4
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M)
Host: www.yahoo.com
--- End http request ---
and some more of these.
Using e.g. 142.250.186.131, this reads different:
dhcps: send_offer>>udp_sendto result 0
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 18 - AP_PROBEREQRECVED
DNS responds: 142.250.186.131 for epdg.epc.mnc002.mcc262.pub.3gppnetwork.org
DNS responds: 142.250.186.131 for connectivitycheck.gstatic.com
DNS responds: 142.250.186.131 for connectivitycheck.gstatic.com
DNS responds: 142.250.186.131 for north-america.pool.ntp.org
DNS responds: 142.250.186.131 for capi.samsungcloud.com
DNS responds: 142.250.186.131 for mtalk.google.com
DNS responds: 142.250.186.131 for alt2-mtalk.google.com
--- Begin http request ---
GET /generate_204 HTTP/1.1
Host: connectivitycheck.gstatic.com
Connection: close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,en;q=0.4
--- End http request ---
DNS responds: 142.250.186.131 for connectivitycheck.gstatic.com
DNS responds: 142.250.186.131 for android.googleapis.com
--- Begin http request ---
GET / HTTP/1.1
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M)
Host: 142.250.186.131
Connection: Keep-Alive
Accept-Encoding: gzip
--- End http request ---
DNS responds: 142.250.186.131 for service.game-mode.net
DNS responds: 142.250.186.131 for android.clients.google.com
--- Begin http request ---
GET /generate_204 HTTP/1.1
Host: connectivitycheck.gstatic.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Linux; Android 7.0; SM-A310F Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.101 Mobile Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
X-Requested-With: com.android.captiveportallogin
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
--- End http request ---
So, the HTTP requests are
GET / HTTP/1.1
Host: 192.168.1.1
(and some other hosts) if using private network address, and
GET /generate_204 HTTP/1.1
Host: connectivitycheck.gstatic.com
if using public network address.
My question:
Is there any reason that android systems act different on addresses from the private address space than from the public one? And if so, is it safe to use e.g. 8.8.4.4
for all kinds of client systems (android, ios, linux, windows, ...)?
Edit:
I tried 10.0.0.1
and 172.16.0.1
(the other two private network spaces), but android does not like them as well; @dandavis seems to be right. Now I use 192.9.200.1
which works well.
Why that address?
Some history: When in the late 1980s and early 1990s companies began to use IP networks in combination with SUN computers, many "network administrators" followed a documentation by SUN how to configure those networks. In that documentation, the address range 192.9.200.0/24
was used as an example; it was part of SUNs own network range. So many (if not all) of those people used this address range, not knowing that they should use other (private) addresses.
The address range 192.9.0.0/16 nowadays is owned by Oracle, but they seem not to use 192.9.200.0/24. If you search for "192.9.200.0", you may still find lots of documentation containing exactly those example addresses.
-
1#2 is a yes. #1 might be that 192.168... looks like a "regular ass wifi" that should be providing internet, whereas 8.8... isn't typical, so this could be a stupid user optimization for the 99.9% of times that 192... provides internet.dandavis– dandavis2021年02月12日 16:45:05 +00:00Commented Feb 12, 2021 at 16:45
-
Thank you for your comment. I really don't like using addresses from internet routed networks for private purpose. But here this might be the only solution - will try 172.16.0.0/12 and 10.0.0.0/8 as well and report on success.ridgy– ridgy2021年02月12日 20:38:56 +00:00Commented Feb 12, 2021 at 20:38
-
I would suggest doing a bit of reading on rouotable and non routable IP addresses. It appears your Android is not on the same network and it is being rejected as it should.Gil– Gil2021年02月15日 21:38:57 +00:00Commented Feb 15, 2021 at 21:38
-
@Gil: Every IPV4 Address is "routable" - there are no "non routable" IP addresses. Addreses out of the "private" address space are not routed in public networks, but that is a different thing (see RFC1918 or en.wikipedia.org/wiki/Private_network). "My Android" gets its Address via DHCP from the Soft-AP, and thus is "in the same network" as the AP, which is also DNS server and default router, as I can see from the Android information.ridgy– ridgy2021年02月26日 10:16:59 +00:00Commented Feb 26, 2021 at 10:16