直接上代码,废话不多说,python3,通过APNIC获取,然后经过计算处理,并取出网络IP和广播IP的形式,用于更新大家的小飞机

author = 'winc'
import requests,re,math
import IPy,ipaddress
def ipaddr(cidrip):
endip=ipaddress.ip_network(cidrip,strict=False).broadcast_address
starip=ipaddress.ip_network(cidrip,strict=False).network_address
return str(starip)+' '+str(endip)
data1=requests.get('http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest')
f=open('D:\soft\chn_ip.txt','w+')
for items in data1.content.decode('utf-8').split('\n'):
if re.search('apnic|CN|ipv4',items):
f.write(ipaddr(items.split('|')[3]+'/'+ str(int(32-math.log(int(items.split('|')[4]),2))))+'\n')
print(ipaddr(items.split('|')[3]+'/'+ str(int(32-math.log(int(items.split('|')[4]),2)))))
f.close()

发表评论

邮箱地址不会被公开。 必填项已用*标注