Dnspython: Setting query timeout/lifetime

前端 未结 1 687
太阳男子
太阳男子 2021-01-11 17:34

I have a small script that checks a large list of domains for their MX records, everything works fine but when the script finds a domain with no record, it takes quite a lon

相关标签:
1条回答
  • 2021-01-11 18:02

    You're setting the timeout after you've already performed the query. So that's not gonna do anything!

    What you want to do instead is create a Resolver object, set its timeout, and then call its query() method. dns.resolver.query() is just a convenience function that instantiates a default Resolver object and invokes its query() method, so you need to do that manually if you don't want a default Resolver.

    resolver = dns.resolver.Resolver()
    resolver.timeout = 1
    resolver.lifetime = 1
    

    Then use this in your loop:

    try:
        domain = row[0]
        query = resolver.query(domain,'MX')
    except:
        # etc.
    

    You should be able to use the same Resolver object for all queries.

    0 讨论(0)
提交回复
热议问题