迷茫2017-04-17 13:36:43
1. ping
may be blocked by the gateway. For example, here we have
2 and 80
ports. Some networks that require authentication, such as ChinaUnicom
’s wifi, will block all 80 ports before logging in. DNAT
Then it redirects to the login page, leading to misjudgment.
3. 443
port. Generally certified networks will not DNAT
this port. Even if it is done, it will cause a certificate error. There are not many domestic HTTPS
websites, and Baidu will also have a certificate under normal circumstances. mistake.
So it is recommended that wget/curl
have a HTTP
page with fixed content, such as http://example.com/
(this domain name really exists), and then judge the content. If different is detected, the user can also be prompted to "Your network" You may need to log in to use". And even if the judgment is wrong, the user experience will be the same.
天蓬老师2017-04-17 13:36:43
How to detect whether he is connected to the external network? This problem itself is difficult to solve because you cannot define "connected to the external network".
So there are only targeted approaches:
This is what Nintendo 3DS does:
get the domain name conntest.nintendowifi.net. If it can be opened and returns to This is test.html page, then 3DS will think that it is connected to the Internet.
The entire process includes domain name resolution and http 80 requests.
As for different environments, it is different. For example, if one day conntest.nintendowifi.net is blocked or banned, this method will not take effect.
Some networks prohibit ping, and the ping method does not work.
天蓬老师2017-04-17 13:36:43
Just like surfing the Internet through a browser, we get the Baidu homepage page to see if there is the word html and the word Baidu:
wget http://www.baidu.com/
will get the html of an index. If there is success, if there is no success, there will be no network. Haha