menu
AMENG
Carpe Diem and Do what I like.
使用ESP8266完成校园网WEB认证

access_time
brush 366个字
whatshot 191 ℃

学校校园网限制连接设备,只能一台手机一台电脑,而要用平板啥的必须先把手机连接断开(万马奔腾)。哪里有压迫哪里就有反抗,于是就想到用路由器拨号解决设备限制问题。学校宿舍区采用锐捷认证,在路由器上安装锐捷认证插件就可以解决,而办公区采用的是卓智的校园网WEB认证,每次打开网页弹出登录页面。
QQ截图20210926182345.jpg
在路由器里没法解决这个问题,只能用电脑打开网页认证,后来用着发现只要路由器下有一台设备认证了,路由器下的其它设备就可以不用认证直接联网了。
但是学校有时晚上会断电,断电后就又得重新认证了,由于电脑上挂着一些服务,断网后远程就没法访问了,于是就打算用ESP8266发送认证包,是路由器连上网。
通过抓包分析发现认证过程就是发送一个post数据,通过fiddler抓取数据后利用esp8266发送认证数据就可以了,通过Ping百度实现断线重连。

#include <ESP8266WiFi.h>
#include <string.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266Ping.h>

struct http_request {  
  String  Referer;
  char* host;
  int httpPort=80;
  String host_ur ;
  String usr_name;
  String usr_pwd;
  String postDate;
  };

http_request ruqest;
 
/*WIFI账号和密码*/
 
const char* ssid = "xxxx";    // Enter SSID here
const char* password = "xxxx";  //Enter Password here
  
/*--------------------------------------------------------------
  通过上网认证,请自己修改postDate中的学号和密码
---------------------------------------------------------------*/
int hdulogin(struct http_request ruqest) {
  WiFiClient client;
 
  if (!client.connect(ruqest.host, ruqest.httpPort)) {
    Serial.println("connection failed");
    return 1;
  }
  delay(10);
 
  if (ruqest.postDate.length() && ruqest.postDate != "0") {
    String data = (String)ruqest.postDate;
    int length = data.length();
 
    String postRequest =
                         (String)("POST ") + "/"+ruqest.host_ur+" HTTP/1.1\r\n" +
                         "Host: " +ruqest.host + "\r\n" +
                         "Connection: Keep Alive\r\n" +
                         "Content-Length: " + length + "\r\n" +
                         "Accept: */*\r\n" +
                         "Origin: http://"+ruqest.host+"\r\n" +
                          "Upgrade-Insecure-Requests: 1"+"\r\n" +
                         "Content-Type: application/x-www-form-urlencoded;" + "\r\n" +
                         "User-Agent: zyzandESP8266\r\n" +
                          "Accept-Encoding: gzip, deflate"+"\r\n" +
                          "Accept-Language: zh-CN,zh;q=0.9"+"\r\n" +                     
                         "\r\n" +
                         data + "\r\n";
    client.print(postRequest);
    delay(600);
    //处理返回信息
    String line = client.readStringUntil('\n');
    while (client.available() > 0) {
      line += "\r\n"+client.readStringUntil('\n');
    }
    Serial.println(line);
    client.stop();
    if (line.indexOf("时间") != -1 || line.indexOf("登陆") != -1) { //认证成功
      return 0;
       Serial.println("time ----------- find ");
    }
    else {
      return 2;
    }
 
  }
  client.stop();
  return 2;
}
 
void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("");
  Serial.println("Connecting to ");
  Serial.println(ssid);
 
  //connect to your local wi-fi network
  WiFi.begin(ssid, password);
 
  //check wi-fi is connected to wi-fi network
  while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

// 认证上网
  ruqest.Referer="http://222.197.192.59:9090/zportal/login/do";
  ruqest.host = "222.197.192.59";
  ruqest.httpPort = 9090;
  ruqest.host_ur = "zportal/login/do";
  ruqest.usr_name="2021111111";//账号
  ruqest.usr_pwd="1111111";//密码 
  ruqest.postDate = String("")+"qrCodeId=请输入编号&username="+ruqest.usr_name+"&pwd="+ruqest.usr_pwd+"&validCode=验证码&validCodeFlag=false&ssid=&mac=ec8c6b0d71bb76d4f28b16895de595e1&t=wireless-v2&wlanacname=7717b8c143d93e3a1fdcfa4aa07d37a9&url=67c2b8eeda616d379b23c9e993a4072517529ecb4c8ab85684da54aea08a8ce06e8fc897829d8d8a&nasip=1223114e4ff3cad74a2437106670b0eb&wlanuserip=5bf3a64063ec6e616ac72003610d8f9c";

  hdulogin(ruqest);
}
 
void loop() 
{
  if(WiFi.status() == WL_CONNECTED){
    bool ret = Ping.ping("www.baidu.com");

    if (ret) {
      // 打印返回代码
      Serial.printf("Success.  Ping=%d\n", ret);
    }
  else {
      Serial.print("failed. Reconnect\n");
      hdulogin(ruqest);
    }
    delay(5000);
}
}

#如无特别声明,该文章均为 AMENG 原创,转载请遵循 署名-非商业性使用 4.0 国际(CC BY-NC 4.0) 协议,即转载请注明文章来源。
#最后编辑时间为: 2021 年 09 月 26 日


create 添加新评论


account_circle
email
language
textsms