Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with DNS queries
#1
In my work I often have to confirm whether devices are in or not in DNS, which, obviously, usually includes using nslookup. Since the list of devices can be rather large, I decided to automate it to some extent with Python and create a GUI around it since the others I work with are not likely to use a command line tool

I have everything built out and in the process of testing I came across a deal breaker of an issue. As you might guess I am using socket.gethostbyname(). The problem is that when a device is not in DNS, there is a huge time delay before the query times out and throws the socket.gaierror. Around 13 seconds to be exact. If it were just one or two devices, this would not be such a big deal, but the list of devices to check can be dozens or more. Often, many of them may no longer be in DNS but we still have to verify that with nslookup.

So, all that said, socket.gethostbyname() is a blocking call. Nothing I have tried thus far seems to get around that time deal. Threading, asyncio, concurrent.futures and so on. I am at my wits end with this and about to just write it off as loss, but a learning experience.

Before I do that, however, I thought I would post here and get input from those that have far more experience with Python than I. I am just having a hard time believing that there is no way around this or that someone has not come across this before and perhaps worked out some solution.

So, does anyone have any ideas before I toss this code off to the side and look for another project to cut my teeth on?
Reply
#2
Well, there is a post that deals with this in detail (on another forum, but were here to help)
here: https://stackoverflow.com/a/8465202

I haven't tried any of these python packages, but you may find one that will help:
https://pypi.org/search/?q=nslookup&o=
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020