Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (64 loc) · 2.58 KB
/
Copy pathmain.py
File metadata and controls
69 lines (64 loc) · 2.58 KB
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
import os
import json
import requests
import netifaces
from dotenv import load_dotenv
def get_local_ip():
"""获取本地IP地址"""
interfaces = netifaces.interfaces()
for interface in interfaces:
if interface == os.getenv("device"):
addrs = netifaces.ifaddresses(interface)
if netifaces.AF_INET in addrs:
return addrs[netifaces.AF_INET][0]['addr']
return None
def generate_login_url(ip, user_account, user_password, wlan_ac_ip, callback="dr1004", login_method="1", wlan_user_ipv6="", wlan_user_mac="000000000000", wlan_ac_name="", js_version="4.1.3", terminal_type="2", lang="zh-cn", v="2041"):
"""生成登录URL并发起请求"""
url = "http://10.0.3.2:801/eportal/portal/login"
params = {
"callback": callback,
"login_method": login_method,
"user_account": user_account,
"user_password": user_password,
"wlan_user_ip": ip,
"wlan_user_ipv6": wlan_user_ipv6,
"wlan_user_mac": wlan_user_mac,
"wlan_ac_ip": wlan_ac_ip,
"wlan_ac_name": wlan_ac_name,
"jsVersion": js_version,
"terminal_type": terminal_type,
"lang": lang,
"v": v,
"lang": lang
}
response = requests.get(url, params=params)
return response
if __name__ == "__main__":
print("[*] Starting login process...")
load_dotenv()
print("[*] Loaded environment variables")
user_account = os.getenv("username")
user_password = os.getenv("password")
print(f"[*] Trying to login with account {user_account} and password {user_password}")
wlan_ac_ip = "172.16.254.2"
# 获取本地IP地址
ip = get_local_ip()
print(f"[*] Local IP address is {ip}")
if ip:
resp = generate_login_url(ip, user_account, user_password, wlan_ac_ip)
try:
resp_json = resp.text.replace("dr1004(", "").replace(");", "")
resp_json = json.loads(resp_json)
if resp_json.get("result") == 1:
print("[*] Login successful!")
else:
print(f"[!] Login failed: {resp_json.get('msg')}(Code: {resp_json.get('result')})")
except json.JSONDecodeError:
print("[!] Failed to decode JSON response")
print(f"[*] Raw response: {resp.text}")
if "Portal协议认证成功!" in resp.text:
print("[*] Detected successful login message in response")
else:
print("[!] Login failed with unknown error")
else:
print("[!] Unable to retrieve local IP address. Please check your network settings.")