Didier Stevens

Monday 25 February 2013

Looking Up Hosts and IP Addresses: Yet Another Tool

Filed under: My Software,Networking — Didier Stevens @ 19:30

One last thing regarding my TeamViewer research: I had to resolve a bunch of hostnames and IP addresses, so I quickly wrote a Python program that did just that. Later I took the time to make some generic and versatile programs: lookup-hosts.py and lookup-ips.py.

lookup-hosts.py takes hostnames or files with hostnames via arguments or stdin, and then uses getaddrinfo to lookup the IP addresses. And you can use a counter if you need to lookup sequentially numbered hosts, like this: master[0-20].teamviewer.com. This will instruct the program to lookup master0.teamviewer.com, master1.teamviewer.com, … and master20.teamviewer.com. If you need a leading zero, use this syntax: master[0-20:2].teamviewer.com

The programs take options, use the -h option to explore them.

As it names implies, lookup-ips.py does the opposite of lookup-hosts.py by using gethostbyaddr. You provide it IP addresses and/or subnets (like X.X.X.X/24).


lookup-tools_V0_0_1.zip (https)
MD5: EB9C5BEF25EC5ED0F44297AA8A04679E
SHA256: 755E98BA0BC09C31E58ED4BF7B08CD42467BBF9B129C77DD6D558FD6B6E27124


  1. Hi Didier,
    I was searching for something like that. Anyway, there’s a drawback:
    File “C:\Python33\IP_lookup\lookup-ips.py”, line 73
    if type(argument) == type(0l) or type(argument) == type(0):
    SyntaxError: invalid syntax
    It seems that type(0l) makes no sense.

    Comment by Anonymous — Tuesday 19 March 2013 @ 7:42

  2. @Snort96 You are using Python 3. My script is for Python 2.

    Comment by Didier Stevens — Tuesday 19 March 2013 @ 12:17

  3. […] It looks like I didn’t release this update to my lookup tools. […]

    Pingback by Update: Lookup Tools | Didier Stevens — Thursday 25 July 2013 @ 20:12

  4. I’m getting the following error returned:

    File “lookup-hosts.py”, line 50
    SyntaxError: invalid syntax

    Comment by Anonymous — Tuesday 30 July 2013 @ 14:13

  5. What version of Python do you use, and on what platform?

    Comment by Didier Stevens — Tuesday 30 July 2013 @ 17:34

RSS feed for comments on this post. TrackBack URI

Leave a Reply (comments are moderated)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.