fewfefffwefweef

This commit is contained in:
27942
2026-01-09 14:40:20 +08:00
parent 1df6d2441b
commit c337027784
148 changed files with 173 additions and 41 deletions

102
test.py
View File

@@ -1,31 +1,81 @@
from curl_cffi import requests
import socket
import psutil
import re
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0',
'Accept': 'application/json, text/plain, */*',
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
'Content-Type': 'application/json',
'sec-ch-ua-platform': '"Windows"',
'sec-ch-ua': '"Microsoft Edge WebView2";v="143", "Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'Origin': 'https://app.depinsim.com',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://app.depinsim.com/',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
}
json_data = {
'initData': 'query_id=AAHKGjNZAwAAAMoaM1n9Jm8g&user=%7B%22id%22%3A7938972362%2C%22first_name%22%3A%22%E7%90%B4%22%2C%22last_name%22%3A%22%E7%8E%8B%22%2C%22username%22%3A%22bgmztfjr%22%2C%22language_code%22%3A%22en%22%2C%22allows_write_to_pm%22%3Atrue%2C%22photo_url%22%3A%22https%3A%5C%2F%5C%2Ft.me%5C%2Fi%5C%2Fuserpic%5C%2F320%5C%2FtfN1ibQBmLhyPRirvlL0SAPLZe2_sJ_ds-9_ibc0e3R5yYVz0M4wOxmltsCJEZ7F.svg%22%7D&auth_date=1767550045&signature=4v_J54Qe9yTFNnkoa69Pq9yy1yiL4H4d8qV354gcSjhogRxFLKJde9pFT44Tb-cVFdqgBgPNFSFk_1l0s1w1Ag&hash=6ede983b3967f128eb1faa217afd7bfedf942312fcf6252ed4192dbb87f451de',
'couponCode': '',
}
class NetworkIPGetter:
"""网络IP获取器"""
response = requests.post('https://api.depinsim.com/base/tgLoginWithCoupon', headers=headers, json=json_data)
def __init__(self):
self.interfaces = psutil.net_if_addrs()
print(response.json()["data"])
def get_wlan_ip(self):
"""获取无线网卡IP优先"""
return self._get_interface_ip(['WLAN', 'Wi-Fi', 'WiFi', 'Wireless'])
def get_ethernet_ip(self):
"""获取有线网卡IP"""
return self._get_interface_ip(['Ethernet', '以太网', 'eth', 'enp'])
def _get_interface_ip(self, keywords):
"""根据关键词查找接口IP"""
for iface_name, addrs in self.interfaces.items():
iface_lower = iface_name.lower()
if any(keyword.lower() in iface_lower for keyword in keywords):
for addr in addrs:
if addr.family == socket.AF_INET:
# 排除一些虚拟/私有地址
if not self._is_virtual_ip(addr.address):
return addr.address
return None
def _is_virtual_ip(self, ip):
"""判断是否为虚拟/私有IP"""
private_patterns = [
r'^127\.', # 回环地址
r'^192\.168\.', # 私有C类
r'^172\.(1[6-9]|2[0-9]|3[0-1])\.', # 私有B类
r'^10\.', # 私有A类
r'^169\.254\.', # 链路本地
]
for pattern in private_patterns:
if re.match(pattern, ip):
return False # 私有IP也是有效的WLAN地址
return False
def get_preferred_ip(self):
"""获取首选网络IP优先WLAN其次有线"""
ip = self.get_wlan_ip()
if not ip:
ip = self.get_ethernet_ip()
return ip or "127.0.0.1"
def get_all_ips(self):
"""获取所有网络接口的IPv4地址"""
result = {}
for iface_name, addrs in self.interfaces.items():
for addr in addrs:
if addr.family == socket.AF_INET:
if iface_name not in result:
result[iface_name] = []
result[iface_name].append({
'address': addr.address,
'netmask': addr.netmask,
'broadcast': addr.broadcast
})
return result
# 使用示例
if __name__ == "__main__":
getter = NetworkIPGetter()
# 获取WLAN IP
wlan_ip = getter.get_wlan_ip()
print(f"WLAN IPv4地址: {wlan_ip}")
# 获取首选IP
main_ip = getter.get_preferred_ip()
print(f"首选IP地址: {main_ip}")
# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
# data = '{"initData":"query_id=AAG-nFE1AwAAAL6cUTWXBDTZ&user=%7B%22id%22%3A7336991934%2C%22first_name%22%3A%22Annie%22%2C%22last_name%22%3A%22Holland%22%2C%22username%22%3A%22dockerse%22%2C%22language_code%22%3A%22zh-hans%22%2C%22allows_write_to_pm%22%3Atrue%2C%22photo_url%22%3A%22https%3A%5C%2F%5C%2Ft.me%5C%2Fi%5C%2Fuserpic%5C%2F320%5C%2FvKyPZp8vuNPAS3qtPTMX5pckp-xCdrOYuct7P6MGse7csZ2PXUs6HeWfQiu7Gzpm.svg%22%7D&auth_date=1767549051&signature=nVXsDAuvmnu-ond_wMmPSXe1ZZVreM3VRxWLMNr2vhBYAyXG40pqz7tgHeaVnMQvP6GrrQ6Z3EWzyxzPdoaxCw&hash=4525486fb5719723dd57b6a0d42785b8085726103ae850b297b4be251af3de6b","couponCode":""}'
# response = requests.post('https://api.depinsim.com/base/tgLoginWithCoupon', headers=headers, data=data)