Skip to content

Instantly share code, notes, and snippets.

@VGostyuzhov
Last active April 7, 2017 11:38
Show Gist options
  • Save VGostyuzhov/4e0e01bfc6c52c526635f67e218367d8 to your computer and use it in GitHub Desktop.
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.
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