您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍关于python批量处理多DNS多域名nslookup的案例分析,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
利用EXCLE生成CSV文档,批量处理nslookup解析。并保存为CSV文档,方便进行查看:
输入文档格式:
data\domain.csv
最终输出文档情况:
data\nlookup.csv
代码:
# coding=gbk import subprocess import csv def get_nslookup(domain, dns): res = subprocess.Popen("nslookup {0} {1}".format(domain, dns), stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[0] response = res.decode("gbk") res_list = response.split("s:") row_nslookup = [domain, dns] row_ip = res_list[2].split()[:-1] row_nslookup.extend(row_ip) return row_nslookup if __name__ == "__main__": file_domain = r'data\domain.csv' # 输入文件 file_nslookup = r'data\nslookup.csv' # 输出文件 with open(file_domain, 'r', newline='', encoding='gbk') as rf: domain_csv = csv.DictReader(rf, dialect=csv.excel) domain_list = [row['domain'] for row in domain_csv] with open(file_domain, 'r', newline='', encoding='gbk') as rf: domain_csv = csv.DictReader(rf, dialect=csv.excel) dns_list = [] for row in domain_csv: print(row['DNS']) if row['DNS'] != '': # 通常DNS数量少于需要监测的域名数量,做去空处理 dns_list.append(row['DNS']) with open(file_nslookup, 'w+', newline='', encoding='gbk') as wf: nslookup_csv = csv.writer(wf, dialect=csv.excel) header = ['domain', 'DNS', 'nslookup_res...'] nslookup_csv.writerow(header) for domain in domain_list: for dns in dns_list: print('解析中:域名:{0}___DNS:{1}'.format(domain, dns)) row_nslookup = get_nslookup(domain, dns) nslookup_csv.writerow(row_nslookup) print('执行完毕')
以上是关于python批量处理多DNS多域名nslookup的案例分析的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。