吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4246|回复: 34
收起左侧

[Python 原创] 利用python实现认证网络一键上线(以校园网为例)

  [复制链接]
Prioritize 发表于 2023-6-13 15:56
本帖最后由 Prioritize 于 2023-6-13 15:59 编辑

校园网认证每次都要输入账号密码很无语,
故不如花费半小时写一个小程序。
先看成品,
代码在文末
图片1.png

主要逻辑就是request的post方法,只不过把账号密码加到里面了而已。
为了好用还用tinker做了一个小界面,加到自启动里,这样一开机点一下就认证上去啦。


写好代码以后cmd里面输入# 打包命令
# pyinstaller -D -w -i 1.ico 搞定校园网.py
就能得到一个自己的小程序了。
另外基于这个思路我做了一个快捷指令有iPhone的朋友可以直接使用
链接:https://www.icloud.com/shortcuts/a162f999ca274b8d8424e8dee5fa3cbb
代码如下:
[Python] 纯文本查看 复制代码
# 导入库
import tkinter as tk
import requests


def click_button():
    # tinker界面上线按钮逻辑函数
    # 进行post请求
    z = requests.post(post_addr, data=post_data, headers=post_header)
    html = z.content.decode('utf-8')
    print(html)
    # 根据返回html进行处理
    if "success" in html:
        if "在线" in html:
            if "当前已用" in html:
                x = html.split('"')[11]
            else:
                x = (html.split('"')[11])[-5:]
        else:
            q = html.split('"')[7]
            x = q + " Y"
    else:
        if "上限" in html:
            z = requests.post(post_addr, data=post_data3, headers=post_header)
            html = z.content.decode('utf-8')
            if "success" in html:
                q = html.split('"')[7]
                x = q + " W"
        else:
            x = html.split('"')[9]
    # 调用提示框
    print(html)
    quit(x)

def click_button2():  # tinker界面下线按钮逻辑函数
    # 进行post请求
    s = requests.post(post_addr2, data=post_data2, headers=post_header2)
    html = s.content.decode('utf-8')
    # 根据返回html进行处理
    x = html.split('"')[7]
    quit(x)

def quit(x):  # 设置提示框以及退出罗辑
    print(x)
    root = tk.Tk()
    root.geometry('400x50+720+560')  # 大小、位置
    root.configure(bg='white')
    root.title('   ')
    tk.Label(root, text=x, justify='left', anchor='nw', font=('楷体', 20), fg='black', bg='white', padx=20,
             pady=10, ).pack()  # 内容的格式和位置
    # 自动退出
    if x[0:2] in ['su', '已经', '下线']:  # quit函数会根据此列表来判断时候成功运行自动关闭
        root.after(700, root.destroy)
        window.after(900, window.destroy)
        return
    root.after(400, root.destroy)


post_data = {  # 上线按钮post方法传入表单
    'userId': '1111111',
    'password': '1111',
    'method': 'login',
    'queryString': 'wlanuserip%3Dba98f72ba688ba1b2e6956adfd675f5f%26wlanacname%3D9849cc5fe582c551d9e3eed4cf0d73c4%26ssid%3D%'
                   '26nasip%3D518f32fe1f6799fd406a10390c7639d5%26snmpagentip%3D%26mac%3Dce72abdafb3b5f373ee63af4e3feb19a%26t%'
                   '3Dwireless-v2%26url%3Df096fb179a85a017da7bcd02fa355b6f2203c39847362bc0%26apmac%3D%26nasid%3D9849cc5fe582c'
                   '551d9e3eed4cf0d73c4%26vid%3Ddce772562596c610%26port%3D2fc6cb63f8cf7590%26nasportid%3D43511eea552cb67d88d6'
                   '841873c14058a52a3c79a14f2a4078dee814504073cb',
    'passwordEncrypt': 'false'
}
post_data2 = {  # 下线按钮post方法传入表单
    'method': 'logout'
}
post_data3 = {  # 上线按钮post方法传入表单
    'userId': '1111111',
    'password': '1111111',
    'method': 'login',
    'queryString': 'wlanuserip%3Dba98f72ba688ba1b2e6956adfd675f5f%26wlanacname%3D9849cc5fe582c551d9e3eed4cf0d73c4%26ssid%3D%'
                   '26nasip%3D518f32fe1f6799fd406a10390c7639d5%26snmpagentip%3D%26mac%3Dce72abdafb3b5f373ee63af4e3feb19a%26t%'
                   '3Dwireless-v2%26url%3Df096fb179a85a017da7bcd02fa355b6f2203c39847362bc0%26apmac%3D%26nasid%3D9849cc5fe582c'
                   '551d9e3eed4cf0d73c4%26vid%3Ddce772562596c610%26port%3D2fc6cb63f8cf7590%26nasportid%3D43511eea552cb67d88d6'
                   '841873c14058a52a3c79a14f2a4078dee814504073cb',
    'passwordEncrypt': 'false'
}
post_addr = "http://172.16.2.100/eportal/InterFace.do?method=login"  # 上线html地址
post_addr2 = "http://172.16.2.100/eportal/InterFace.do?method=logout"  # 下线html地址
post_header = {  # 模拟浏览器访问
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive',
    'Content-Length': '632',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'EPORTAL_COOKIE_OPERATORPWD=; EPORTAL_COOKIE_SERVER=; EPORTAL_AUTO_LAND=; EPORTAL_COOKIE_DOMAIN=; EPORTAL_C'
              'OOKIE_SERVER_NAME=; EPORTAL_COOKIE_USERNAME=; EPORTAL_COOKIE_PASSWORD=; EPORTAL_COOKIE_SAVEPASSWORD=false; '
              'EPORTAL_USER_GROUP=2020%E7%BA%A7%E6%9C%AC%E7%A7%91; JSESSIONID=27ADED1AF4049155790B8130E68EDACE',
    'Host': '172.16.2.100',
    'Origin': 'http://172.16.2.100',
    'Referer': 'http://172.16.2.100/eportal/index.jsp?wlanuserip=ba98f72ba688ba1b2e6956adfd675f5f&wlanacname=9849cc5fe582'
               'c551d9e3eed4cf0d73c4&ssid=&nasip=518f32fe1f6799fd406a10390c7639d5&snmpagentip=&mac=ce72abdafb3b5f373ee63'
               'af4e3feb19a&t=wireless-v2&url=f096fb179a85a017da7bcd02fa355b6f2203c39847362bc0&apmac=&nasid=9849cc5fe582'
               'c551d9e3eed4cf0d73c4&vid=dce772562596c610&port=2fc6cb63f8cf7590&nasportid=43511eea552cb67d88d6841873c140'
               '58a52a3c79a14f2a4078dee814504073cb',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safa'
                  'ri/537.36 Edg/107.0.1418.35',
}
post_header2 = {  # 模拟浏览器访问
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate ',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive ',
    'Content-Length': '128 ',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8 ',
    'Cookie': 'EPORTAL_COOKIE_OPERATORPWD=; EPORTAL_COOKIE_SERVER=; EPORTAL_AUTO_LAND=; EPORTAL_COOKIE_DOMAIN=; EPORTAL_'
              'COOKIE_SERVER_NAME=; EPORTAL_COOKIE_USERNAME=; EPORTAL_COOKIE_PASSWORD=; EPORTAL_COOKIE_SAVEPASSWORD=false'
              '; EPORTAL_USER_GROUP=null; JSESSIONID=46F12FF101FA64ADA050C3C962B35718 ',
    'Host': '172.16.2.100 ',
    'Origin': 'http://172.16.2.100 ',
    'Referer': 'http://172.16.2.100/eportal/success.jsp?userIndex=3531386633326665316636373939666434303661313033393063373'
               '6333964355f31302e3130302e35352e3130315f303232393030323030333437 ',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Saf'
                  'ari/537.36 Ed ',
}
window = tk.Tk()  # 设置主界面
window.title(''), window.geometry('600x150+600+500')  # 设置标题、大小、偏移量
window.configure(bg='white')
tk.Button(  # 设置tinker界面上线按钮
    window, text='上线',
    font=("得意黑", 50,),
    fg='#177cb0', bg='white',
    relief="flat",
    command=click_button).pack(expand=True, fill="both", side="left")
tk.Button(  # 设置tinker界面下线按钮
    window, text='下线',
    font=("得意黑", 50, ),
    fg='#177cb0', bg='white',
    relief="flat",
    command=click_button2).pack(expand=True, fill="both", side="left")
window.mainloop()  # 输出

免费评分

参与人数 6吾爱币 +12 热心值 +6 收起 理由
binlin002 + 1 + 1 我很赞同!
CYLmtthhh + 1 + 1 热心回复!
Xuzhu123 + 1 + 1 热心回复!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
menoooooos + 1 + 1 我很赞同!
blindcat + 1 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

lingwushexi 发表于 2023-6-19 10:17
学习一下
jianmo 发表于 2023-6-17 09:42
我学校校园网只需要curl一下关键包就行了  用bat写一下然后丢到自启动就行 每次开机就能自动连校园网了
52soft 发表于 2023-6-13 16:33
blindcat 发表于 2023-6-13 16:49
学习一下
wfys66 发表于 2023-6-13 17:00
锐捷网络  可以用嘛?
Dlan 发表于 2023-6-13 17:58
还得点一下,差评
zhang7069 发表于 2023-6-13 18:11
有用的知识又增加了,感谢楼主
歪喇叭 发表于 2023-6-13 19:19
感谢分享
Shimmer666 发表于 2023-6-13 20:19
queryString咋获取呢
DigitalGap 发表于 2023-6-13 20:45
很实用,感谢
moruye 发表于 2023-6-13 20:59
学习学习,感谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 07:37

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表