连上Wi-Fi 热点自动弹窗的实现方法
当我们连上某个热点, 会自动弹出登录窗口的专业名称叫做: Captive portal
原理, 实现方式有三种
1 : dns 跳转, 在热点上面实现配置, 把所有dns请求返回都配置为:服务器地址 ;服务器有404跳转或者DNS url跳转 , 跳转到的界面即为自动弹出登录界面;
2 : http跳转,对所有的http请求返回302或者301或者404跳转, 跳转到的界面即为自动弹出登录界面;
3 : ip跳转,既把所有的ip包里的目标地址改为认证服务器,然后在认证服务器上做404跳转
第三种实现起来比较麻烦, 我们要实现第一种和第二种 Captive portal;
配置本地服务器
使用NodeJS搭建一个本地WEB服务器, 服务器端口为默认的80, 无论访问服务器的任意地址 都有正常200返回,app.use函数是精华.., 然后使用node app.js启动服务器:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var http = require("http");
var index = require('./routes/index'); var app = express(); app.set('views', path.join(__dirname, 'views')); app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false })); app.use('/', index);
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); //该函数是关键 , 如论用户访问任何页面 , 都会重定向到本地index.html文件
app.use(function(req, res, next) {
res.status = ;
res.redirect('/index.html');
}); http.createServer(app).listen();
使用HTTP跳转
本机环境是kali系统, 外加一个usb网卡, 使用以下代码实现热点:
#!/bin/bash
## quick and dirty AP with hostapd and dnsmasq
## exit properly with ctrl-c echo "Exit this script with Ctrl-C and it will attempt to clean up properly." if [ -z $ ]; then
echo -n "SSID: "
read ssid
else
ssid=$
fi # get wep key
function get_wep_key() {
echo -n "WEP Key [must be exactly 5 or 13 ascii characters]: "
read wep_key
if [[ $wep_key =~ ^[a-zA-Z0-]{}$ ]] ; then
echo "Key accepted"
elif [[ $wep_key =~ ^[a-zA-Z0-]{}$ ]] ; then
echo "Key accepted"
else
echo "WEP key must be exactly 5 or 13 characters"
get_wep_key
fi
} # get mac
function get_mac() {
echo -n "Enter MAC address in the following format AB:CD:EF:12:34:56: "
read new_mac
if [[ $new_mac =~ ^[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}$ ]] ; then
macchanger --mac=$new_mac wlan0
else
echo "MAC Address format not correct."
get_mac
fi
} # ask for WEP
echo -n "Do you want WEP enabled? [y/n]: "
read wep
case $wep in
y*)
get_wep_key
;;
*)
;;
esac # ask for MAC change
echo -n "Do you want to change your MAC? [y/n]: "
read changemac
case $changemac in
y*)
echo -n "Custom MAC? [y/n]: "
read random_mac
case $random_mac in
y*)
get_mac
;;
n*)
macchanger -r wlan0
;;
*)
echo "Invalid choice, keeping current MAC address."
;;
esac
;;
n*)
;;
esac # install packages if need be
if [ $(dpkg-query -W -f='${Status}' dnsmasq >/dev/null | grep -c "ok installed") -eq ];
then
apt-get install dnsmasq
fi
if [ $(dpkg-query -W -f='${Status}' hostapd >/dev/null | grep -c "ok installed") -eq ];
then
apt-get install hostapd
fi # trap control c
trap ctrl_c INT function ctrl_c() {
echo "wlan0 managed mode"
iwconfig wlan0 mode managed
echo "downing wlan0"
ifconfig wlan0 down
echo "flushing firewall"
iptables -F
iptables -F -t nat
echo "resetting wlan0 mac"
macchanger -p wlan0
kill - `cat /tmp/dnsmasq.run`
} ## script begins # stop and disable services
service hostapd stop
service dnsmasq stop
pkill - dnsmasq
pkill - hostapd # bring up wlan0
nmcli radio wifi off
rfkill unblock wlan
iwconfig wlan0 mode monitor
ifconfig wlan0 10.0.0.1/ up # forwarding and nat
sysctl -w net.ipv4.conf.all.route_localnet=
iptables -t nat -I PREROUTING -p tcp --dport -j DNAT --to 10.0.0.1: # dns masq conf
cat > /tmp/dnsmasq.conf <<!
bind-interfaces
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.254
! # hostapd conf
cat > /tmp/hostapd.conf<<!
interface=wlan0
driver=nl80211
ssid=${ssid}
hw_mode=g
channel=
! # if WEP key, add to hostapd conf
if [[ -n $wep_key ]]; then echo -e "wep_default_key=0\nwep_key0=\"${wep_key}\"" >> /tmp/hostapd.conf; fi # run dnsmasq and hostapd
dnsmasq --pid-file=/tmp/dnsmasq.run -C /tmp/dnsmasq.conf
hostapd /tmp/hostapd.conf
以上代码中:
sysctl -w net.ipv4.conf.all.route_localnet=1
iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to 10.0.0.1:80
是本例子的精华所在, 第一句的意思是指所有的ipv4请求全部重定向到本地, 第二句的意思为所有准备访问本地80端口的机器,全部指向到10.0.0.1的80端口, 而我们本地的80端口为我们部署的服务器, 这样即可实现 Captive portal
使用DNS跳转
在本地网关搭建DNS服务器, 局域网内部的所有DNS请求全部返回10.0.0.1
sh文件代码如下:
#!/bin/bash
## quick and dirty AP with hostapd and dnsmasq
## exit properly with ctrl-c echo "Exit this script with Ctrl-C and it will attempt to clean up properly." if [ -z $ ]; then
echo -n "SSID: "
read ssid
else
ssid=$
fi # get wep key
function get_wep_key() {
echo -n "WEP Key [must be exactly 5 or 13 ascii characters]: "
read wep_key
if [[ $wep_key =~ ^[a-zA-Z0-]{}$ ]] ; then
echo "Key accepted"
elif [[ $wep_key =~ ^[a-zA-Z0-]{}$ ]] ; then
echo "Key accepted"
else
echo "WEP key must be exactly 5 or 13 characters"
get_wep_key
fi
} # get mac
function get_mac() {
echo -n "Enter MAC address in the following format AB:CD:EF:12:34:56: "
read new_mac
if [[ $new_mac =~ ^[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}:[a-fA-F0-]{}$ ]] ; then
macchanger --mac=$new_mac wlan0
else
echo "MAC Address format not correct."
get_mac
fi
} # ask for WEP
echo -n "Do you want WEP enabled? [y/n]: "
read wep
case $wep in
y*)
get_wep_key
;;
*)
;;
esac # ask for MAC change
echo -n "Do you want to change your MAC? [y/n]: "
read changemac
case $changemac in
y*)
echo -n "Custom MAC? [y/n]: "
read random_mac
case $random_mac in
y*)
get_mac
;;
n*)
macchanger -r wlan0
;;
*)
echo "Invalid choice, keeping current MAC address."
;;
esac
;;
n*)
;;
esac # install packages if need be
if [ $(dpkg-query -W -f='${Status}' dnsmasq >/dev/null | grep -c "ok installed") -eq ];
then
apt-get install dnsmasq
fi
if [ $(dpkg-query -W -f='${Status}' hostapd >/dev/null | grep -c "ok installed") -eq ];
then
apt-get install hostapd
fi # trap control c
trap ctrl_c INT function ctrl_c() {
echo "wlan0 managed mode"
iwconfig wlan0 mode managed
echo "downing wlan0"
ifconfig wlan0 down
echo "flushing firewall"
iptables -F
iptables -F -t nat
echo "resetting wlan0 mac"
macchanger -p wlan0
kill - `cat /tmp/dnsmasq.run`
} ## script begins # stop and disable services
service hostapd stop
service dnsmasq stop
pkill - dnsmasq
pkill - hostapd # bring up wlan0
nmcli radio wifi off
rfkill unblock wlan
iwconfig wlan0 mode monitor
ifconfig wlan0 10.0.0.1/ up #dhcp
iptables --policy INPUT ACCEPT
iptables --policy FORWARD ACCEPT
iptables --policy OUTPUT ACCEPT
iptables -F
iptables -t nat -F
iptables -t nat -A PREROUTING -i wlan0 -p udp --dport -j DNAT --to 10.0.0.1 # dns masq conf
cat > /tmp/dnsmasq.conf <<!
bind-interfaces
interface=wlan0
address=/#/10.0.0.1
dhcp-range=10.0.0.2,10.0.0.254
dhcp-option=,10.0.0.1 #DNS
dhcp-option=,10.0.0.1 #Gateway
dhcp-option=,"http://wpad.example.com/wpad.dat\n" #WPAD
dhcp-authoritative
! # hostapd conf
cat > /tmp/hostapd.conf<<!
interface=wlan0
driver=nl80211
ssid=${ssid}
hw_mode=g
channel=
! # if WEP key, add to hostapd conf
if [[ -n $wep_key ]]; then echo -e "wep_default_key=0\nwep_key0=\"${wep_key}\"" >> /tmp/hostapd.conf; fi # run dnsmasq and hostapd
dnsmasq --pid-file=/tmp/dnsmasq.run -C /tmp/dnsmasq.conf
hostapd /tmp/hostapd.conf
其中以下代码尤为重要:
bind-interfaces
interface=wlan0
address=/#/10.0.0.1 《==这个配置说明为所有dns请求都返回10.0.0.1
dhcp-range=10.0.0.2,10.0.0.254 《==客户机器IP池
dhcp-option=6,10.0.0.1 #DNS 《==本地DNS服务器
dhcp-option=3,10.0.0.1 #Gateway 《==本地网关
dhcp-option=252,"http://wpad.example.com/wpad.dat\n" #WPAD
dhcp-authoritative
参考
dnsmasq参考API :https://wiki.archlinux.org/index.php/dnsmasq
Captive portal是怎样强制弹出窗口的呢? : https://www.zhihu.com/question/38843766
作者: NONO
出处:http://www.cnblogs.com/diligenceday/
企业网站:http://www.idrwl.com/
开源博客:http://www.github.com/sqqihao
QQ:287101329
微信:18101055830
厦门点燃未来网络科技有限公司, 是厦门最好的微信应用, 小程序, 微信网站, 公众号开发公司
连上Wi-Fi 热点自动弹窗的实现方法的更多相关文章
- DedecmsV5.7本地上传缩略图无法自动添加水印的解决方法
问题:dedecms后台 系统->图片水印设置 图片水印设置有开启了,但是本地上传缩略图无法自动添加水印 网上有很多资料,所以记录一下 1.打开dede(实际项目后台文件夹)/archives_ ...
- Dedecms本地上传缩略图无法自动添加水印的解决方法
客户遇到一个问题,DEDECMS(V5.7)后台添加文档时,本地上传缩略图无法自动添加水印(系统设置里的图片水印设置没有问题),找了半天,终于找到了解决方法,留个记号: 打开dede/archives ...
- 手机连接wifi自动弹窗的原理及其实现方案
一.手机连上wifi后会自动弹窗的原理 生活中,有很多需要认证的路由器,手机连接wifi热点后会自动弹出一个网页,让用户输入账号和密码,比如星巴克,肯地基,麦当劳,甚至是火车站和机场的候车室.其实这是 ...
- 手机连上wifi热点后自动弹窗的功能
使用buildroot编译bind DNS服务器 用buildroot来制作文件系统很方便,编译出来的文件系统是直接可用的,不用添加脚本等麻烦的工作,很多的库和app都可以直接添加到文件系统里边,如常 ...
- 艺萌文件上传下载及自动更新系统(基于networkComms开源TCP通信框架)
1.艺萌文件上传下载及自动更新系统,基于Winform技术,采用CS架构,开发工具为vs2010,.net2.0版本(可以很容易升级为3.5和4.0版本)开发语言c#. 本系统主要帮助客户学习基于TC ...
- 艺萌TCP文件上传下载及自动更新系统介绍(TCP文件传输)(一)
艺萌TCP文件上传下载及自动更新系统介绍(TCP文件传输) 该系统基于开源的networkComms通讯框架,此通讯框架以前是收费的,目前已经免费并开元,作者是英国的,开发时间5年多,框架很稳定. 项 ...
- winrar在右键菜单上加上:打包自动加上日期时间标签【图文教程】 - imsoft.cnblogs
说明: 注册表HKEY_CURRENT_USER\Software\WinRAR\Profiles\0找到GenerateArcName修改0为1,修改GenerateMask为你想要的日期式(默认 ...
- 在 uniGUI 中实现自动弹窗后延迟几秒关闭 — Toast 功能
在 uniGUI 中实现自动弹窗后延迟几秒关闭 — Toast 功能. uniGUI 的客户端使用 EXTJS 6 ,本就有 Toast 功能. 但UniGui 官方没有相应的控件,我们如何使用 EX ...
- 在windows 上自动重启 tomcat 的方法
在windows 上自动重启 tomcat 的方法 实现思路: Windows 上监控tomcat 进程并且自动重启的脚本 一类是 定时重启 tomcat 一类是 监控并重启 写一个守护tomcat进 ...
随机推荐
- vijos1034题解
题目: 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如果x,y是亲 ...
- c# 上传附件大小限制的问题
在c# 相关的asp.net 中.需要设置附件的大小.需要修改2部分. 1.修改metabase.XML 以Windows2003 为例子. 打开 C:\Windows\System32\Inets ...
- 简单的小程序实现ATM机操作
简单的小程序实现ATM机操作 代码如下: package Day06; import java.util.Scanner; public class TestAccount { public stat ...
- python全栈阶段测试(一)
1.执行Python脚本的两种方式 如果想要永久保存代码,就要用文件的方式 如果想要调试代码,就要用交互式的方式 2.Pyhton单行注释和多行注释分别用什么? 单行注释:# 多行注释: '' &qu ...
- jmeter 单接口测试方案(接口无业务关联)
前言 前面开了一篇讲了Jenkins+jmeter+ant的使用,但没有说到具体怎么投入到项目使用,主要介绍了接口测试定义,流程和环境部署,所以我今天要说的就是我是怎么将这个方案投入到实际中使用的.这 ...
- WEB安全:文件上传漏洞
文件上传漏洞过程 用户上传了一个可执行的脚本文件,并通过此脚本文件获得了执行服务器端命令的能力. 一般的情况有: 上传文件WEB脚本语言,服务器的WEB容器解释并执行了用户上传的脚本,导致代码执行: ...
- MyBatis+mysql 简单分页
注意:limit不能跟动态内容 <select id="fenYe" parameterType="int" resultType="com.x ...
- MySQL系列(二)---MySQL事务
MySql 事务 目录 MySQL系列(一):基础知识大总结 MySQL系列(二):MySQL事务 什么是事务(transaction) 保证成批操作要么完全执行,要么完全不执行,维护数据的完整性.也 ...
- 天地图使用过程中由于display:none导致加载部分地图瓦片失败
在为按钮添加点击事件让地图显示的时候,初始加载未加载到当前页面尺寸的所有地图瓦片,在display:none之后停止加载地图,所以display:none属性去掉,改为dom解析完成之后$('#map ...
- 【RequireJS】requireJS的基础知识
1. requirejs的优点 1)异步加载依赖的文件 2)管理文件加载顺序 3)管理文件加载的包路径 2. requirejs下载地点 https://github.com/jrburke/requ ...