0

I am trying to send a dns query to an specific dns resolver in python.

Here is my code to set my resolver and sending my dns query to find the ip address of my domain name:

import dns.resolver #import the module
myResolver = dns.resolver.Resolver()
myResolver.nameservers = ['my resolver ip address']
myResolver.port = 5300#port number of resolver listening to dns queries
myAnswers = myResolver.query("google.com")
print myAnswers

This code works very well when I receive just one response from the resolver. The response can has multiple ip addresses and that is ok too. The question is that, my dns resolver has been configured to send multiple response to a A dns query and I need to receive first, second and third one and check them and if one of them passed my checks, print the response in the console. My problem is that I do not know how can I get multiple responses with myAnswers = myResolver.query("google.com") command. Because this command return the response and save that in myAnswer. I know I should use multithreading and listen to incoming responses from my dns resolver. But I do not know how I can run my thread with this command,myAnswers = myResolver.query("mytargetdomain.com",'a')? Thanks.

  • Multiple queries are possible with multiple connections. How do you get multiple data with a single connection? – dsgdfg Dec 13 '17 at 21:09
  • Not Multiple queries. I will receive multiple response from the server. and just for your information, dns uses udp which is a connectionless protocol. What I need right now is that I send my query with raw socket and then run a thread in the background to listen to incomming packets. I do not know how implement that. – Shahrooz Pooryousef Dec 13 '17 at 22:02

0 Answers0