How do we do DNS query in Python -
how dns query, expecially mx query, in python not installing third party libs.
i want query mx record domain, however, seems socket.getaddrinfo
can query record.
i have tried this:
python -c "import socket; print socket.getaddrinfo('baidu.com', 25, socket.af_inet, socket.sock_dgram)"
this prints
[(2, 2, 17, '', ('220.181.57.217', 25)), (2, 2, 17, '', ('123.125.114.144', 25)), (2, 2, 17, '', ('180.149.132.47', 25))]
however, can not telnet telnet 220.181.57.217 25
or telnet 123.125.114.144 25
or telnet 180.149.132.47 25
.
first install dnspython
import dns.resolver answers = dns.resolver.query('dnspython.org', 'mx') rdata in answers: print 'host', rdata.exchange, 'has preference', rdata.preference
Comments
Post a Comment