百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

自动连接公共WIFI(一):连接方法分析

zhezhongyun 2024-12-03 06:27 67 浏览

朋友有一台电脑需要连接公共WIFI,该WIFI支持账号登录、手机验证码登录和微信登录,但是一次登录成功后,第二天早上会自动清理登录账号,因此需要一个方法每天自动登录WIFI。之前朋友使用Python爬虫方法模拟用户点击输入账号和密码登录,但是经常出现无法正常连接的状况,于是找我看看如何优化。

1、 在浏览器中输入www.baidu.com,会自动跳转到WIFI登录认证界面。

curl www.baidu.com

使用curl模拟,获取返回的页面信息如下:

<html>
<head>
<script type="text/javascript">location.href="http://10.131.6.1:8080/wsmAuth/iportal/?usermac=34-F7-16-79-XX-XX&userip=10.131.50.166&ssid=FREE%2dWIFI&nasip=10%2e131%2e6%2e1&devType=v7"</script>
</head>
<body>
Authentication is required. Click <a href="http://10.131.6.1:8080/wsmAuth/iportal/?usermac=34-F7-16-79-XX-XX&userip=10.131.50.166&ssid=FREE%2dWIFI&nasip=10%2e131%2e6%2e1&devType=v7">here</a> to open the authentication page.
</body>
</html>

其中usermac和userip是当前电脑的mac地址和自动获取的IP。

2、使用chrome调试模式获取账户登录form提交内容。

可以看到该form使用post方法向/wsmAuth/login提交了一堆参数,其中重要的是username(用户名)、signature(密码)、usermac(mac地址)、userip(ip地址)、ssid(wifi名称)、nasip(认证服务器IP)、devType(设备类型)、userAgreement(登录协议勾选)。

以上参数用户名密码我们有,其他参数均可以从跳转页面链接中获取。

3、测试直接提交登录认证是否可以登录成功。

curl http://10.131.6.1:8080/wsmAuth/login -X POST -d "operateType=7&signature=XXXXXX&userName=135xxxxxxxx&userAgreement=1&rabbit=h3c&templateId=7&redirect_uri=null&apmac=null&usermac=34-F7-16-79-XX-XX&userip=10.131.50.166&userurl= &shopid=1&groupid=0&authCfgid=1&ssid=FREE-WIFI&basip=null&nasid=null&wlannasid=null&wlanssid=null&userPublicIp=null&nasip=10.131.6.1&devType=v7&ipmAuthType=1&authPage=/themeTemplate/1638770462964/auth.xml&onebutton=0&userLabel=&needWechat=1"

登录成功!

HTTP/1.1 200 OK
Content-Type: text/json;charset=UTF-8
Content-Length: 179
{"succurl":"http://10.131.6.1:8080/wsmAuth/succ_page.jsp?templateId=7&shopid=1&ssid=FREE-WIFI&succpage=/themeTemplate/1638770462964/complete.xml&groupid=0&userLabel="}

使用上面的方法登录成功说明该WIFI认证并没有COOKIE、REFERE等验证,这将简化自动登录程序。我们完全不需要用朋友写的模拟浏览器点击的方案了,代码量和代码复杂度极大降低!

4、 再次访问www.baidu.com测试网络是否正常。

可以正常访问外网!

curl www.baidu.com -i

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 2381
Content-Type: text/html
Date: Tue, 15 Mar 2022 02:31:09 GMT
Etag: "588604eb-94d"
Last-Modified: Mon, 23 Jan 2017 13:28:11 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>?2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a>  <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号  <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

总结:

通过上面几个简单的步骤,成功模拟了使用用户名密码登录该WIFI的步骤,接下来就是写一个脚本自动登录了。

自动登录脚本思路如下:

  1. 循环访问www.baidu.com网址,如果成功获取到百度页面,则网络在线。
  2. 若1中返回的是WIFI认证页面,则解析该链接,获取我们需要的参数
  3. 拼接认证页面需要的参数,提交WIFI认证,解析返回结果判断是否认证成功

具体代码将使用Python的requests编写,详见下篇文章。

连载:自动连接公共WIFI(二):python脚本自动连接

相关推荐

perl基础——循环控制_principle循环

在编程中,我们往往需要进行不同情况的判断,选择,重复操作。这些时候我们需要对简单语句来添加循环控制变量或者命令。if/unless我们需要在满足特定条件下再执行的语句,可以通过if/unle...

CHAPTER 2 The Antechamber of M de Treville 第二章 特雷维尔先生的前厅

CHAPTER1TheThreePresentsofD'ArtagnantheElderCHAPTER2TheAntechamber...

CHAPTER 5 The King&#39;S Musketeers and the Cardinal&#39;S Guards 第五章 国王的火枪手和红衣主教的卫士

CHAPTER3TheAudienceCHAPTER5TheKing'SMusketeersandtheCardinal'SGuard...

CHAPTER 3 The Audience 第三章 接见

CHAPTER3TheAudienceCHAPTER3TheAudience第三章接见M.DeTrévillewasatt...

别搞印象流!数据说明谁才是外线防守第一人!

来源:Reddit译者:@assholeeric编辑:伯伦WhoarethebestperimeterdefendersintheNBA?Here'sagraphofStea...

V-Day commemorations prove anti-China claims hollow

People'sLiberationArmyhonorguardstakepartinthemilitaryparademarkingthe80thanniversary...

EasyPoi使用_easypoi api

EasyPoi的主要特点:1.设计精巧,使用简单2.接口丰富,扩展简单3.默认值多,writelessdomore4.springmvc支持,web导出可以简单明了使用1.easypoi...

关于Oracle数据库12c 新特性总结_oracle数据库12514

概述今天主要简单介绍一下Oracle12c的一些新特性,仅供参考。参考:http://docs.oracle.com/database/121/NEWFT/chapter12102.htm#NEWFT...

【开发者成长】JAVA 线上故障排查完整套路!

线上故障主要会包括CPU、磁盘、内存以及网络问题,而大多数故障可能会包含不止一个层面的问题,所以进行排查时候尽量四个方面依次排查一遍。同时例如jstack、jmap等工具也是不囿于一个方面的问题...

使用 Python 向多个地址发送电子邮件

在本文中,我们将演示如何使用Python编程语言向使用不同电子邮件地址的不同收件人发送电子邮件。具体来说,我们将向许多不同的人发送电子邮件。使用Python向多个地址发送电子邮件Python...

提高工作效率的--Linux常用命令,能够决解95%以上的问题

点击上方关注,第一时间接受干货转发,点赞,收藏,不如一次关注评论区第一条注意查看回复:Linux命令获取linux常用命令大全pdf+Linux命令行大全pdf为什么要学习Linux命令?1、因为Li...

linux常用系统命令_linux操作系统常用命令

系统信息arch显示机器的处理器架构dmidecode-q显示硬件系统部件-(SMBIOS/DMI)hdparm-i/dev/hda罗列一个磁盘的架构特性hdparm-tT/dev/s...

小白入门必知必会-PostgreSQL-15.2源码编译安装

一PostgreSQL编译安装1.1下载源码包在PostgreSQL官方主页https://www.postgresql.org/ftp/source/下载区选择所需格式的源码包下载。cd/we...

Linux操作系统之常用命令_linux系统常用命令详解

Linux操作系统一、常用命令1.系统(1)系统信息arch显示机器的处理器架构uname-m显示机器的处理器架构uname-r显示正在使用的内核版本dmidecode-q显示硬件系...

linux网络命名空间简介_linux 网络相关命令

此篇会以例子的方式介绍下linux网络命名空间。此例中会创建两个networknamespace:nsa、nsb,一个网桥bridge0,nsa、nsb中添加网络设备veth,网络设备间...