1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| ''' 创建者:李展旗 创建时间:2023-03-19 本开源声明禁止删除,如有二创请保留原作者声明,开源协议MIT '''
import requests import socket import os ##在这几个变量换成你的信息 ##如使用ipconfig/all获取的mac是这样——>'00-50-56-C0-00-02',但是设置变量时尽量把横线去掉设置成这样的'005056C00002'
username='' #你的学号 passwd='' #你的身份证后六位 wifi_mac='' #你的wifi网卡的物理地址 eth_mac='' #你的以太网网卡的物理地址
#下面这两个可以保持默认,如果因为这两个值无法联网.....那就再找我要段会自动获取tsid 的程序(这部分代码不公开) eth_tsid='167617406600511025' wifi_tsid='167650842600680627'
## 不能执行解绑mac的操作 ##使用socket获取当前连接的ip ip=socket.gethostbyname(socket.gethostname())
#实例化请求session对象 s=requests.session() #构造请求头 headers={'User-Agent': 'lizhanqi_9602', 'X-Requested-With': 'XMLHttpRequest', 'Referer': 'http://10.79.254.101:9080/pcportal/login-smx.html', 'Accept': 'application/json, text/javascript, */*; q=0.01' }
#通过系统调用,返回以太网的连接状态 ss=os.popen("ipconfig/all").readlines() txt=ss[ss.index('以太网适配器 以太网:\n')+2]
#判断是否是wifi连接,注意不能是wifi和以太网都没有连接,否则requests将报无法连接的错误 if '媒体已断开连接' in txt: wifi=True else: wifi=False
#判断是wifi连接还是以太网连接,并为他们准备连接时需要的数据 if wifi: ##wifi data={'tsid': wifi_tsid, 'authtype': '1', 'username': username, 'password': passwd, 'usertype': '1', 'lang': '', 'FunName': 'ncSrvLogin', 'userip': ip, 'wlanacname': '2222.0000.000.00.460', 'ssid': 'SMXPT', 'usermac': wifi_mac, 'nasid': 'SMXPT'} else: ##eth data={'FunName': 'ncSrvLogin', 'tsid': eth_tsid, 'authtype': '', 'username': username, 'password': passwd, 'mobno': '', 'mobpass': '', 'mobtype': '2', 'usertype': '1', 'lang': '', 'userip': ip, 'wlanacname': '2224.0000.000.00.460', 'ssid': 'GONET-LAN', 'usermac': eth_mac, 'nasid': 'GONET-LAN'}
#提交请求 html=s.post('http://10.79.254.101:9080/pronline/Msg',headers=headers,data=data) if 'System Busy or Not Ready' not in html.text: print('当前你的连接是:{},连接成功!'.format('wifi' if wifi else 'eth'))
|