Can python module handle an answer of DNS query?

Hello

Having python module i want to record queries and answers to MySQL database. From example1,2 i know how to get queries like “example.com” but don’t yet know which python variable can get me answer of IP address list from respond. Is it possible with python module to do this?

Sorry for my English and thanks in advance.

BR Rishat

You can do this in ldns, but may find it easier to do in ldnsx (http://oldwww.xelerance.com/ldnsx/html/). Using the convenience function get_rrs() we can do:

import ldnsx
ip_addr = ldnsx.get_rrs(“example.com”,“A”)[0].ip()

Though you’ll get an exception if there aren’t any A records.

Alternatively, you could not use convenience functions and do:

import ldnsx
res = ldnsx.resolver()
pkt = res.query(“example.com”,“A”)
ans = pkt.answer()
ip_addr = ans[0].ip()

Christopher