-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfd.py
45 lines (36 loc) · 1.41 KB
/
fd.py
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
import requests
def get_cloudflare_colo(ip_address):
# API URL
url = f"https://proxyip.edtunnel.best/api?ip={ip_address}&host=speed.cloudflare.com&port=443&tls=true"
# 模拟真实浏览器的请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.9',
'Connection': 'keep-alive',
}
try:
# 发送GET请求
response = requests.get(url, headers=headers)
response.raise_for_status() # 检查请求是否成功
# 打印服务器返回的内容(调试用)
print("服务器返回的内容:", response.text)
# 解析JSON响应
try:
data = response.json()
colo = data.get('colo', 'Unknown')
return colo
except ValueError as e:
print(f"JSON解析失败: {e}")
return None
except requests.exceptions.RequestException as e:
print(f"请求失败: {e}")
return None
# 示例IP地址
ip_address = "149.129.8.215"
# 获取colo信息
colo = get_cloudflare_colo(ip_address)
if colo:
print(f"IP地址 {ip_address} 的Cloudflare colo是: {colo}")
else:
print("无法获取colo信息")