欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python批量處理多DNS多域名的nslookup解析實(shí)現(xiàn)

 更新時(shí)間:2020年06月28日 14:44:28   作者:風(fēng)月無心2002  
這篇文章主要介紹了python批量處理多DNS多域名的nslookup解析實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(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)測(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)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論