[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')
#根据返回html进行处理
if "success" in html:
if "在线" in html:
if "当前已用" in html:
x = html.split('"')[11]
else:
x = (html.split('"')[11])[-5:]
else:
x = html.split('"')[7]
else:
if "上限" in html:
x = (html.split('"')[9])[13:]
else:
x = html.split('"')[9]
print(html.split(",")[1])
print(html.split(",")[2])
#调用提示框
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]
print(html.split(",")[1])
quit(x)
def quit(x):
# 设置提示框以及退出罗辑
root = tk.Tk()
root.geometry('400x50+720+560') # 大小、位置
root.title(' ')
tk.Label(root, text=x, justify='left', anchor='nw', font=('楷体', 18), fg='black', 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方法传入表单[color=#000000]
'userId': '123',
'password': '123',
'method': 'login',
'queryString': 'wlanuserip%3Dba98f72ba688ba1b2e6956adfd675f5f%26wlanacname%3D9849cc5fe582c551d9e3eed4cf0d73c4%26ssid%3D%'
'26nasip[/color]%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_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')#设置标题、大小、偏移量
tk.Button(#设置tinker界面上线按钮
window,text='上线',
font=("宋体",40,"bold"),
fg='#e0eee8',bg='#5698c3',
relief="ridge",
command=click_button).pack(expand=True, fill="both", padx=10, pady=10, side="left")
tk.Button(#设置tinker界面下线按钮
window,text='下线',
font=("宋体",40,"bold",),
fg='#e0eee8',bg='#5698c3',
relief="ridge",
command=click_button2).pack(expand=True, fill="both", padx=10, pady=10, side="left")
window.mainloop()#输出