Problems copying the package "dns" in Python

0

I have a problem in a script where I need to use the dns package in Python.

import dns.resolver

And to perform a simple DNS check:

my_resolver = dns.resolver.Resolver()
my_resolver.nameservers = ['8.8.8.8']
records = my_resolver.query(domain, 'MX')

I have already installed the package, and continue with the following error:

    records = my_resolver.query(domain, 'MX')
  File "build/bdist.linux-x86_64/egg/dns/resolver.py", line 1036, in query
  File "build/bdist.linux-x86_64/egg/dns/resolver.py", line 233, in __init__
dns.resolver.NoAnswer: The DNS response does not contain an answer to the question: uol.com.br. IN MX

Any tips?

    
asked by anonymous 12.09.2016 / 22:37

1 answer

0
import dns.resolver

def lista_mx(hosts):
    return ['\n'.join(map(str,[resul for resul in [dns.resolver.query(host, 'MX') for host in hosts][i]])) for i in range(hosts.__len__())]
if __name__ == "__main__":
    hosts = ['google.com','uol.com.br','hawksec.com.br']
    for i in lista_mx(hosts):
        print(i)

40 alt3.aspmx.l.google.com.
20 alt1.aspmx.l.google.com.
30 alt2.aspmx.l.google.com.
10 aspmx.l.google.com.
50 alt4.aspmx.l.google.com.
10 mx.uol.com.br.
10 webserver01.floripa.com.br.

link

    
13.09.2016 / 16:11