Created
June 9, 2011 19:04
-
-
Save bricef/1017458 to your computer and use it in GitHub Desktop.
Script to do a hostname lookup on an IP address. Batteries included.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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