Created
March 17, 2023 09:16
-
-
Save luoboQAQ/a7a42d915b28327a06aa1a9c808f4f45 to your computer and use it in GitHub Desktop.
G-core测速相关脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
def formatIp(ip): | |
return ip.replace('/32', '').replace('/128', '').replace('\'', '') | |
IS_GET_IPV4 = True | |
IS_GET_IPV6 = True | |
FILE_PATH = 'gcore_mix.txt' | |
r = requests.get('https://api.gcdn.co/cdn/public-ip-list') | |
v4 = r.json()['addresses'] | |
v6 = r.json()['addresses_v6'] | |
sys.stdout = open(FILE_PATH, "w") | |
if IS_GET_IPV4: | |
for ip in v4: | |
print(formatIp(ip)) | |
if IS_GET_IPV6: | |
for ip in v6: | |
print(formatIp(ip)) | |
sys.stdout.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import requests | |
from requests.adapters import HTTPAdapter | |
# 设置超时重试次数 | |
s = requests.session() | |
s.mount('http://', HTTPAdapter(max_retries=3)) | |
s.mount('https://', HTTPAdapter(max_retries=3)) | |
with open('result.csv', encoding="utf-8") as csvfile: | |
reader = csv.reader(csvfile, delimiter=',') | |
reader.__next__() | |
ipList = [] | |
for row in reader: | |
print('正在获取' + row[0] + '的位置信息') | |
r = s.get('https://api.vore.top/api/IPdata?ip=' + row[0], timeout=5) | |
ipInform = r.json() | |
# print(r.text) | |
print(ipInform['adcode']['o']) | |
ipList.append({ | |
'ip': row[0], | |
'delay': row[4], | |
'speed': row[5], | |
'country': ipInform['adcode']['o'], | |
}) | |
print('IP'.ljust(30) + '延迟'.ljust(10) + '速度'.ljust(10) + '国家') | |
for ip in ipList: | |
print(ip['ip'].ljust(30) + ip['delay'].ljust(10) + ip['speed'].ljust(10) + ip['country']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment