• 注册
  • 转载分享 转载分享 关注:153 内容:10420

    利用python实现认证网络一键上线工具 Python源码(以校园网为例)

  • 查看作者
  • 打赏作者
  • 当前位置: 七七博客 > 转载分享 > 正文
    • 4
    • 转载分享
    • 利用python实现认证网络一键上线工具 Python源码(以校园网为例)

      说明

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

      使用

      1、写好代码以后cmd里面输入# 打包命令。

      # pyinstaller -D -w -i 1.ico 搞定校园网.py

      2、就能得到一个自己的小程序了。

      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()  # 输出

      隐藏内容需要回复可以看见

      回复
      Lv.6
      ​楼主辛苦了,谢谢楼主,楼主好人一生平安!
      回复
      Lv.11

      楼主辛苦了,谢谢楼主,楼主好人一生平安!

      回复

      楼主辛苦了,谢谢楼主,楼主好人一生平安!

      回复
      ​楼主辛苦了,谢谢楼主,楼主好人一生平安!
      回复

      请登录之后再进行评论

      登录
    • 任务系统
    • 帖子间隔 侧栏位置: