1.处理zone文件
A.先格式化区文件数据,去掉不需要的数据,生成新的文件 com.zone.sample
cat com.zone |grep -P IN' 'NS|awk -F ' ' '{print $1","$4}' >> com.zone.sample
格式如下:
waiyuren.com.,ns6.ctrlcache.com.
jmtcq.com.,ns5.myhostadmin.net.
B.获取到所有的ns数据,并且去重,并生成新的文件/home/cnzone/com_sort.zone
cat com.zone |grep -P IN' 'NS|awk -F ' ' '{print $4}'|sort|uniq >> com_sort.zone
格式如下:
zyd1.dnspod.net.
zyd.dnspod.net.
zz.baidu.com.
C.如果com_sort.zone文件比较大,最好按行分成多分文件,同时运行脚本
详见:[linux 查看某几行内容与文件分割] (https://www.cnblogs.com/wt11/p/9351021.html)
2.批量dig ns,获取支持ipv6的ns
[root@localhost home]# cat dns.py
import sh
import json
ns = {}
def validation_ipv6(domain):
ns = {}
num = 0
try:
dig = sh.dig(domain, "AAAA", "+short")
num = sh.wc(dig, "-l")
print(domain +'-----------------------'+ str(int(num)))
except:
with open('unreachd_domain.txt', 'a+', encoding='utf8') as f2:
f2.write(domain + '
')
if int(num) > 0:
ns[domain] = int(num)
#print(ns)
datas = json.dumps(ns, ensure_ascii=False, indent=4)
with open('ipv6_ns.txt', 'a+', encoding='utf8', buffering=1) as ff:
ff.write(datas+',')
def save():
with open('cn.ns.sort', 'r', encoding='utf8') as f:
for i in f:
i = i.strip()
validation_ipv6(i)
if __name__ == '__main__':
save()
3.根据对应的ns,获取支持ipv6的网站
[root@localhost home]# cat get_v6.py
import json
alls = {}
def ana():
with open('ipv6_ns.txt', 'r', encoding='utf8') as f:
data = json.load(f)
for item in data:
for key in item:
alls[key] = item[key]
def gets():
n = 0
with open('com.zone.sample', 'r', encoding='utf8') as ff:
for line in ff:
line = line.strip()
key = line.split(',')[1]
num = alls.get(key, 0)
print(str(n) + '-------------->'+ line +'------------>' + key + '>>>>>>>' + str(num))
n = n + 1
if num > 0:
with open('support_ipv6_site.txt', 'a+', encoding='utf8') as fc:
fc.write(line.split(',')[0] + '
')
if __name__ == '__main__':
ana()
gets()