Last active
April 7, 2017 11:38
-
-
Save VGostyuzhov/4e0e01bfc6c52c526635f67e218367d8 to your computer and use it in GitHub Desktop.
Resolve IP address for each hostname from file and save it to the new file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dns.resolver | |
with open('hostnames.txt', 'r') as file, open('result_resovle.csv', 'wb') as outfile: | |
for line in file: | |
try: | |
answers = dns.resolver.query(line.strip(), 'A') | |
for rdata in answers: | |
outfile.write(line.strip() + ':' + rdata.to_text() + '\n') | |
except: | |
outfile.write(line.strip() + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment