您好,登錄后才能下訂單哦!
這篇文章主要介紹關(guān)于python批量處理多DNS多域名nslookup的案例分析,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
利用EXCLE生成CSV文檔,批量處理nslookup解析。并保存為CSV文檔,方便進(jìn)行查看:
輸入文檔格式:
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數(shù)量少于需要監(jiān)測的域名數(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的案例分析的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。