Issue
New to python and I am using Python 3.7
I have a list of domains. I wanna read these domains from a text file and then check nslookup. But this code is not working. What's wrong with this code? Please let me know the solution.
import dns.resolver,os
new_txt = open("Domain_check.txt","w")
with open(os.getcwd()+"\\\Domains.txt", "r") as f:
for date in f:
dateb = str(date)
dateb = dateb.replace("\n"," ")
answers = dns.resolver.resolve(dateb, 'A')
for rdate in answers:
b = str(dateb) + str(rdate)
new_txt.write(b)
My Domain list is : google.com、yam.com
Solution
The error message The DNS query name does not exist: yahoo.com\032.
gives a hint: there's an additional character at the end of the address. This is because when you read the Domains.txt file, you replace the linebreaks with a space - incidentally, that's code 32 in ASCII. Do this instead:
import dns.resolver
with open("Domains.txt", "r") as in_file, \
open("Domain_check.txt", "w") as out_file:
for line in in_file:
qname = line.strip()
answers = dns.resolver.resolve(qname, 'A')
for rdata in answers:
output = domain + ' ' + str(rdata)
out_file.write(output)
I fixed a few other issues with the code. Please feel free to ask if anything is unclear.
Answered By - Jan Wilamowski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.