0
import dns.resolver
import concurrent.futures
domains=open('com 2021-6-7 domains.txt',encoding='utf-8').read().splitlines()[0:10000]


mx_domains=[]


def check(domain):
    try:
        answers = dns.resolver.resolve(domain, 'MX')
        print('MX EXISTS')
        mx_domains.append(domain)
    except Exception as e:
        print(e)
        print('No MX')




with concurrent.futures.ThreadPoolExecutor(max_workers=500) as executor:
    executor.map(check, domains)

Why is this code giving error:

The DNS operation timed out after 5.005800008773804 seconds

Also is there a way to solve this problem or perhaps a better way to do it? or is it something to do with my network? I am new to the area of Networking so I am not able to understand why is this even causing a timeout error?

shahrOZe
  • 105
  • 1
  • 5
  • Do you have the same problem when doing the DNS query yourself, like with `dig`? In normal life it can totally happen that a DNS server is not responding and hence you get a timeout. There is not a lot you can do against that, just do your architecture in such a way that you retry later if relevant and/or you really try all authoritative nameservers to get a reply. – Patrick Mevzek Jun 13 '21 at 18:53
  • I used google's 8.8.8.8 server and it gave less timedout errors but they were there.. how can i use multiple nameservers.. for example if one gave a timed out error i can use another server. Also can i get blocked if i send too many requests? – shahrOZe Jun 14 '21 at 08:07
  • "how can i use multiple nameservers.. " Depend on the DNS client. A full resolver will try all possible authoritative nameservers. "Also can i get blocked if i send too many requests? " Yes, theoretically possible if you hammer a nameserver. Yet, rare. The typical method of rate limiting called RRL will drop some queries and reply to others with the DNS truncated flag. – Patrick Mevzek Jun 14 '21 at 14:39

0 Answers0