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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| import json import os import random import re import time
import requests
class CampusNetwork(): def __init__(self): self.url = 'http://192.168.200.2:801/' self.ac = '' self.user_account = ',0,1673111@telecom' self.user_password = '123456789'
self.callback = 'dr1003' self.v = random.randint(1000, 9999) self.jsVersion = '3,3.3' self.my_result, self.my_ipv4 = self.check_status() self.headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.5", "Connection": "keep-alive", "Referer": self.url, }
def login(self): params = { 'c': 'Portal', 'a': 'login', 'callback': 'dr1004', 'login_method': '1', 'user_account': self.user_account, 'user_password': self.user_password, 'wlan_user_ip': self.my_ipv4, 'wlan_user_ipv6': '', 'wlan_user_mac': '000000000000', 'wlan_ac_ip': '', 'wlan_ac_name': '', 'jsVersion': self.jsVersion, 'v': self.v } url = self.url + 'eportal/' resp = requests.get(url, params=params) print(resp.text)
def check_status(self): url = 'http://192.168.200.2/drcom/chkstatus' params = { "callback": self.callback, "v": self.v } resp = requests.get(url, params=params).text content = json.loads(re.search(r'dr\d+\((\{.*?\})\)', resp).group(1)) my_result = content["result"] my_v46ip = content["v46ip"] return my_result, my_v46ip
def timing_campus_net(self): if not self.my_result: self.login()
def check_wifi(): response = os.system(f"ping -c 1 -W 1 192.168.200.2 > /dev/null 2>&1") return response == 0
if __name__ == '__main__': for _ in range(15): flag = check_wifi() if flag: a = CampusNetwork() a.timing_campus_net() break time.sleep(1)
|