Skip to content

Instantly share code, notes, and snippets.

@bricef
Created June 9, 2011 19:04
Show Gist options
  • Save bricef/1017458 to your computer and use it in GitHub Desktop.
Save bricef/1017458 to your computer and use it in GitHub Desktop.
Script to do a hostname lookup on an IP address. Batteries included.
#!/usr/bin/env python
import sys
from socket import gethostbyaddr, herror
def usage():
print("[usage]: %s [ip]"%(sys.argv[0]))
print("")
print("performs a reverse lookup on a host ip.")
if __name__ == "__main__":
if len(sys.argv) > 1 :
try:
print("name = %s"%gethostbyaddr(sys.argv[1])[0])
except herror:
print("NOT FOUND")
else:
usage()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment