Pandas dns csv
Jump to navigation
Jump to search
#!/usr/bin/env python3 import csv import sys import dns.resolver import numpy as np import time import pandas as pd def query_dns_a_record(domain, resolver_ip): # print(domain) # print(resolver_ip) ext = dns.resolver.Resolver(configure=False) ext.nameservers = ['8.8.8.8'] try: result = ext.resolve(domain, 'A') return [str(rdata) for rdata in result] except (dns.resolver.NoAnswer, dns.resolver.NXDOMAIN): # print(f"Could not resolve {domain}") return [] def strip_quotes(val): return val.replace('"', '') def get_cname(): df = pd.read_csv('CNAME.csv', converters={i: strip_quotes for i in range(100)}) for index, row in df.iterrows(): # print(row['Name'], row['Data']) records = query_dns_a_record(row['Data'], "8.8.8.8") print(f"{row['Data']} {records}") # time.sleep(5) def get_a(): df = pd.read_csv('A.csv', converters={i: strip_quotes for i in range(100)}) for index, row in df.iterrows(): if "66.133" in row['Data']: print(f"{row['Name']}.{row['Zone']} {row['Data']}") def xget_a(filename, mstring): with open(filename, 'r') as csvfile: csvreader = csv.reader(csvfile) for row in csvreader: if mstring in row[3]: print(row[1], row[3]) # get_a() get_cname()