-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolochecker.py
More file actions
50 lines (39 loc) · 1.11 KB
/
colochecker.py
File metadata and controls
50 lines (39 loc) · 1.11 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
import re
import requests
from threading import Thread
def check_colo(ip):
url = 'http://' + str(ip) + '/cdn-cgi/trace'
try:
res = requests.get(url, timeout=5) # 设置超时时间
pattern = r'colo=(\w+)'
# 使用 re.search 来查找匹配项
match = re.search(pattern, res.text)
if match:
extracted_value = match.group(1)
return extracted_value
else:
return None
except Exception as e:
return None
def worker(ip):
list.append({"ip": ip, "colo": check_colo(ip)})
def main():
threads = []
list = []
file = open('cnout', 'r')
ips = file.readlines() # 一次性读取所有IP地址
# 创建并启动线程
for ip in ips:
ip = ip.strip('\n')
thread = Thread(target=worker, args=(ip,))
threads.append(thread)
thread.start()
# 等待所有线程完成
for thread in threads:
thread.join()
file.close()
for item in list:
if item['colo']:
print('IP:', item['ip'], 'Colo:', item['colo'])
if __name__ == '__main__':
main()