Problems copy "dns" package in Python

Asked

Viewed 117 times

1

I have a problem with 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 already installed the package, and I 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 hint?

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.

http://www.dnspython.org/examples.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.