Gcore CDN 优选 IP(获取指定延迟范围的IP)
Gcore CDN 优选 IP(获取指定延迟范围的IP)
Gcore CDN 官方 IP 列表: https://api.gcorelabs.com/cdn/public-ip-list
import requests as rs;
import ipaddress as ip
from ping3 import ping as ping
def getGcoreIPList():
src = 'https://api.gcorelabs.com/cdn/public-ip-list'
resp = rs.get(src)
if resp.status_code == 200:
data = resp.json()
IPList = data['addresses']
return IPList
def traceIp(IPList):
saveIplist = '.\\iplist.txt'
with open(saveIplist, 'w') as filewriteIp:
for cidrip in IPList:
net = ip.ip_network(cidrip)
for i in net:
print(i)
filewriteIp.writelines(str(i) + '\n')
filewriteIp.close()
# print(i)
def getCidrIpByPost(cidrIp):
cidrSrc = 'https://www.sioe.cn/xinqing/CIDRShow.php'
data = {
"cidr" : cidrIp,
"qh" : "cidr",
"token" : "babe1bdf4438dc60c1ee3e399485ca9a",
"v" : 4
}
res = rs.post(url=cidrSrc, data=data)
print(res)
print(res.text)
print(res.content)
def getCidrIp(cidrIp):
net = ip.ip_network(cidrIp)
for i in net:
print(i)
def getPingResult():
iplist = "iplist.txt"
result = ".\\result.txt"
with open(iplist, 'r') as fileread:
with open(result, 'w', encoding='utf-8') as filewrite:
level = 200.0
for ip in fileread:
ip = ip.replace('\n', '')
# print("获取到IP为:" + str(ip))
pingtime = ping(ip, timeout=1, unit='ms')
if not pingtime:
pingtime = 5000.0
if (pingtime < level):
res = ip + " ping延迟为 " + str(int(pingtime)) + 'ms'
print(res)
filewrite.write(res + '\n')
# print(pingresult)
filewrite.close()
fileread.close()
def getPingResultByIp(ip):
res = ping(ip, timeout=1, unit='ms')
print(res)
if __name__ == "__main__":
# iplist = getGcoreIPList()
# traceIp(iplist)
# cidrip = "87.120.164.6/32"
# getCidrIp(cidrip)
getPingResult()
# ip = "5.188.7.17"
# getPingResultByIp(ip)
Gcore CDN 优选 IP(获取指定延迟范围的IP)
本博客所有文章除特别声明外,均采用
CC BY-NC-SA 4.0
许可协议。转载请注明来自 Hi I'm LouisLan!
评论
0 评论