Code Monkey home page Code Monkey logo

auto-connect-school-network's Introduction

前言

寝室安装了一个路由器, 但是不知道什么原因, 每天都会断开连接, 需要手动认证一下才可以, 为了避免不必要的麻烦, 写了这样一个小的python脚本来自动的重连

本文设计的操作有一定的上手难度, 不太适合对计算机完全不懂的同学使用, 如有需求, 可私聊

源码解析

主函数非常的简单:

if __name__ == '__main__':
    while True:
        if pong():
            time.sleep(5)
        else:
            login()
            time.sleep(10)

每个5秒检查自己还能不能上网, 方式就是ping 8.8.8.8, 这是很常见的方法.

如果不能上网, 那么就调用login()函数来自动重连

我们的校园网认证的过程,本质上就是提交一个HTTP请求, 那我们的login()函数, 其实就是实现了这个过程, 因此我们只需要知道,我们的网页端认证 是怎么操作的即可,麻烦的是华科的校园网的代码设计的还是很复杂的,所以还是稍微的耗费了一点时间.

校园网认证流程

首先我们进入这个认证的页面, 按F12进入开发者模式

我们会在Source中看到两个重要的JS文件,当我们点击网页中的连接 Login的时候就会调用这个函数.

img_1.png

这个函数会收集你的一系列信息,并最终调用:AuthInterFace.login

img_2.png

AuthInterFace定义在 AuthInterFace.js中.

其中init()用于生成请求的url, login()首先将传入的参数合并成content,最后通过post方法发送请求

img_3.png

因此需要我们做的就是, 获取content的内容, 然后我们就可以用python对指定的url发起post请求

获取content的方法也很简单, 只需要在如图位置打上断点, 然后点击网页中连接的按钮,当js执行到断点后,就可以复制content的值

img_4.png

使用

  1. git clone https://github.com/Kingdo777/auto-connect-school-network.git

  2. 我们将上一过程获取到的content信息存放到main.py的同目录下的名为content的文件中

  3. 然后就可以执行python脚本了

  4. 不过windows下需要安装npcap, 可以点击以下链接下载安装

    https://nmap.org/npcap/dist/npcap-1.60.exe

后记

  1. 如果切换了Wifi, 导致IP地址改变, 那么需要重新获取content的值.

auto-connect-school-network's People

Contributors

kingdo777 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

auto-connect-school-network's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.