You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
auto/archive/check/check_ip_origin.py

66 lines
2.1 KiB

# -*- coding: utf-8 -*-
import aiohttp
import asyncio
import json
target_ip = '175.99.17.215' # 目标IP地址
async def fetch(session, url, headers, payload):
# 发送POST请求
async with session.post(url, headers=headers, data=payload) as response:
response_text = await response.text()
print(response_text)
# 解析JSON数据
data = json.loads(response_text)
# 打印获取到的数据
print(data)
# 将数据中的中文编码转换为中文字符
text_data = data.get('text', {})
for key, value in text_data.items():
if isinstance(value, str):
text_data[key] = value.encode('latin1').decode('utf-8')
data['text'] = text_data
return data
async def main():
# 爬虫目标URL
url = 'https://tool.lu/ip/ajax.html'
# 请求头
headers = {
'accept': 'application/json, text/javascript, */*; q=0.01',
'accept-encoding': 'gzip, deflate, br, zstd',
'accept-language': 'zh-CN,zh;q=0.6',
'content-length': '16',
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'origin': 'https://tool.lu',
'priority': 'u=1, i',
'referer': 'https://tool.lu/ip/',
'sec-ch-ua': '"Brave";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'sec-gpc': '1',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'x-requested-with': 'XMLHttpRequest'
}
# 要发送的数据
payload = f'{target_ip}'
# 创建aiohttp会话
async with aiohttp.ClientSession() as session:
# 调用fetch函数
result = await fetch(session, url, headers, payload)
# 打印结果
print(json.dumps(result, ensure_ascii=False, indent=2))
# 运行异步主函数
loop = asyncio.get_event_loop()
loop.run_until_complete(main())