python批量處理多DNS多域名的nslookup解析實(shí)現(xiàn)
利用EXCLE生成CSV文檔,批量處理nslookup解析。并保存為CSV文檔,方便進(jìn)行查看:
輸入文檔格式:
datadomain.csv
最終輸出文檔情況:
datanlookup.csv
代碼:
# coding=gbkimport subprocessimport 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’datadomain.csv’ # 輸入文件 file_nslookup = r’datanslookup.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數(shù)量少于需要監(jiān)測(cè)的域名數(shù)量,做去空處理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(’執(zhí)行完畢’)
到此這篇關(guān)于python批量處理多DNS多域名的nslookup解析實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)python 批量多域名nslookup內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 詳解CSS偽元素的妙用單標(biāo)簽之美2. 使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁(yè)的方法3. HTML5 Canvas繪制圖形從入門到精通4. XHTML 1.0:標(biāo)記新的開端5. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究6. 利用CSS3新特性創(chuàng)建透明邊框三角7. asp(vbscript)中自定義函數(shù)的默認(rèn)參數(shù)實(shí)現(xiàn)代碼8. ASP基礎(chǔ)知識(shí)VBScript基本元素講解9. JSP的Cookie在登錄中的使用10. XML入門的常見問題(四)
