没有弹出 Android 手机的强制门户 [英] Captive Portal for Android Phone did not pop up

查看:32
本文介绍了没有弹出 Android 手机的强制门户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 hostapd、dnsmasq 和 apache2 在我的 Raspberry Pi 3B+ 上实现了带有强制门户的 wifi 热点,在我实施这个项目之前,我从未接触过 wifi 网络.因此我搜索了很多关于如何实现一个的帖子.

I used hostapd, dnsmasq and apache2 for implementing the wifi-hotspot with captive portal on my Raspberry Pi 3B+, before I implement this project, I have never get in touch with wifi networks. Hence I search a lot of post on how to implement one.

以下是我使用的配置:

/etc/apache/apache.conf:

/etc/apache/apache.conf:

# Apple
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^CaptiveNetworkSupport(.*)$ [NC]
RewriteCond %{HTTP_HOST} !^192.168.0.200$
RewriteRule ^(.*)$ http://192.168.0.200/index.html [L,R=302]

# Android
RedirectMatch 302 /generate_204 http://192.168.0.200/index.html

# All
RewriteCond %{REQUEST_URI} !=/index.html
RewriteRule ^(.*)$ http://192.168.0.200/index.html [L]

# 404 Redirect
ErrorDocument 404 http://192.168.0.200/index.html

/etc/dnsmasq.conf:

/etc/dnsmasq.conf:

interface=wlan0
dhcp-range=192.168.0.201,192.168.0.210,255.255.255.0,24h
address=/#/192.168.0.200

我使用了 Sony H4133、HUAWEI RNE-22、Redmi Note3、Samsung Galaxy S8+、Samsung Galaxy Tab S 来测试门户.只有索尼才能像魅力一样工作.Tab S 可以弹出通知,但是当我点击它时,它会将我发送到 google.com 而不是我的门户.而其他人甚至没有显示弹出窗口.

I used Sony H4133, HUAWEI RNE-22, Redmi Note3, Samsung Galaxy S8+, Samsung Galaxy Tab S to test the portal. Only the Sony one work like a charm. Tab S can pop up a notification but when I click on it, it send me to google.com but not my portal. While others didn't even show the pop up.

我检查了 access.log 并发现/generate_204 确实是 302 重定向到我的页面并返回 200 代码.根据我的研究,除了 204 之外的任何代码返回都应该显示弹出窗口,但为什么这里不是这种情况?

I checked the access.log and find that the /generate_204 indeed 302 redirect to my page and return a 200 code. According to my research, any code return other than 204 should show up the pop up, but why it is not the case here?

访问日志:

192.168.0.204 - - [04/Jan/2020:12:20:10 +0800] "GET /index.html HTTP/1.1" 200 899 "-" "MQ 3.3.8/3.0 (Android 6.0.1) Xiaomi Redmi Note 3"
192.168.0.204 - - [04/Jan/2020:12:20:11 +0800] "GET /generate_204 HTTP/1.1" 302 561 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Redmi Note 3 MIUI/V10.2.1.0.MHOMIXM)"
192.168.0.204 - - [04/Jan/2020:12:20:15 +0800] "POST /getconfig HTTP/1.1" 302 531 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Redmi Note 3 MIUI/V10.2.1.0.MHOMIXM)"
192.168.0.204 - - [04/Jan/2020:12:20:15 +0800] "GET /index.html HTTP/1.1" 200 862 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Redmi Note 3 MIUI/V10.2.1.0.MHOMIXM)"
192.168.0.204 - - [04/Jan/2020:12:20:15 +0800] "POST /mistats/v2 HTTP/1.1" 302 531 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Redmi Note 3 MIUI/V10.2.1.0.MHOMIXM)"
192.168.0.204 - - [04/Jan/2020:12:20:15 +0800] "GET /index.html HTTP/1.1" 200 862 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Redmi Note 3 MIUI/V10.2.1.0.MHOMIXM)"
192.168.0.204 - - [04/Jan/2020:12:20:20 +0800] "POST /mistats/v2 HTTP/1.1" 302 531 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Redmi Note 3 MIUI/V10.2.1.0.MHOMIXM)"
192.168.0.204 - - [04/Jan/2020:12:20:20 +0800] "GET /index.html HTTP/1.1" 200 862 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Redmi Note 3 MIUI/V10.2.1.0.MHOMIXM)"



192.168.0.205 - - [04/Jan/2020:12:23:31 +0800] "GET /generate_204 HTTP/1.1" 302 570 "-" "Dalvik/2.1.0 (Linux; U; Android 8.0.0; RNE-L22 Build/HUAWEIRNE-L22)"
192.168.0.205 - - [04/Jan/2020:12:23:31 +0800] "GET /generate_204 HTTP/1.1" 302 560 "-" "Dalvik/2.1.0 (Linux; U; Android 8.0.0; RNE-L22 Build/HUAWEIRNE-L22)"
192.168.0.205 - - [04/Jan/2020:12:23:31 +0800] "GET /generate_204 HTTP/1.1" 302 560 "-" "Dalvik/2.1.0 (Linux; U; Android 8.0.0; RNE-L22 Build/HUAWEIRNE-L22)"
192.168.0.205 - - [04/Jan/2020:12:23:44 +0800] "GET /generate_204 HTTP/1.1" 302 570 "-" "Dalvik/2.1.0 (Linux; U; Android 8.0.0; RNE-L22 Build/HUAWEIRNE-L22)"
192.168.0.205 - - [04/Jan/2020:12:23:56 +0800] "GET /generate_204 HTTP/1.1" 302 570 "-" "Dalvik/2.1.0 (Linux; U; Android 8.0.0; RNE-L22 Build/HUAWEIRNE-L22)"

推荐答案

apache.conf 是你的问题.以另一种方式配置 Apache2.
每个操作系统都有自己不同的互联网访问检测方式.

apache.conf is your problem. Config Apache2 in another way.
Every operating system has its own different way of detecting Internet access.

机制基本上是这样的:

GET/POST http://x.com/bar.html
If bar.html == [expected content] > Open Internet
If bar.html != [expected content] > Captive Portal
If bar.html[status] != SUCCESS > No Network  

每个设备,Android 不同的制造商,行为不同.例如,看看这个列表:

Each device, also Android different manufactures, behaves differently. For example, look at this list:

xperia z5:
connectivitycheck.gstatic.com:80
clients3.google.com:80
---------------------
galaxy j3 2016:
172.217.21.14:80    connectivitycheck.android.com
---------------------
galaxy j7 2015:
172.16.98.10:80
connectivitycheck.gstatic.com:80
---------------------
galaxy note4:
nothing!
---------------------
ios 11:
captive.apple.com/hotspot-detect.html
---------------------
windows 10:
www.msftconnecttest.com

我建议为每个设备/制造商制作另一个 apache 配置文件.

I suggest make another apache config file for each device/manufacture.

在apache中为android创建目录

Create a directory for android in apache

cd /var/www/html/
sudo mkdir android 

创建一个简单的 index.html 文件,该文件将出现在 android 设备的启动页面上.

Create a simple index.html file that is going to appear on the splash page of the android device.

在 nano(或您喜欢的文本编辑器)中创建 android.conf 并复制以下代码为 Android 设备创建重定向规则".

Create android.conf in nano (or your favorite text editor) and copy the following code to create a "redirection rule" for Android devices.

sudo nano /etc/apache2/sites-enabled/android.conf  

把这些行:

<VirtualHost *:80>

    Servername connectivitycheck.gstatic.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/android

    RedirectMatch 302 /generate_204 /index.html

    ErrorLog ${APACHE_LOG_DIR}/android_error.log
    CustomLog ${APACHE_LOG_DIR}/android_access.log combined

</VirtualHost>

保存文件并退出.

完成.按照其他设备的步骤操作.此外,请查看此链接以获取更多信息.

Done. Follow the procedure for other devices. Also, check this link out to get more information.

这篇关于没有弹出 Android 手机的强制门户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆