I'm trying to automate some of the tasks with python. I have to chcek if some domains are still in ours DNS servers. So searching through stack i found script with dns.resolver and tryied to suit it to my needs. So, the script looks like this:
import socket import dns.resolver mylist=[] with open('domainfile.txt') as file: for line in file: mylist.append(line) length = len(mylist) resolver = dns.resolver.Resolver() resolver.nameservers=[socket.gethostbyname('dns.example.com')] for i in range(length): for rdata in resolver.query(mylist[i], 'CNAME') : print(rdata.target) My domainfile.txt looks like this:
domain1 domain2 domain3 [...] And error message i recived is:
Traceback (most recent call last): File "dnspython.py", line 20, in for rdata in resolver.query(lista[i], 'CNAME') : File "/usr/local/lib/python3.7/dist-packages/dns/resolver.py", line 1053, in query raise_on_no_answer) File "/usr/local/lib/python3.7/dist-packages/dns/resolver.py", line 236, in init raise NoAnswer(response=response) dns.resolver.NoAnswer: The DNS response does not contain an answer to the question: domain1\010.example.com. IN CNAME
If I just insert my domain inside if statement instead of iterate through the mylist I get what I need. But when I try to do it through the list it adds to my domain \010 and then nothing happens. Can you help me with this? Thanks!
domainfile.txt? I think this might be the problem.file <filename>text/plain; charset=us-asciifile. Do you recommend to change it to utf-8 or something else?