Thursday, August 29, 2013

Reverse Lookup - Python Style

I won't claim to be a master of Python, but thought I'd share some quick scripts I've written from my readings and hacking together snips from what I've found online.  Hopefully this will inspire others to learn a scripting language.  The code is not perfect, and I will probably want to include some error checking at some point.

#!/usr/bin/python

import optparse
import socket
from socket import *

def rlookup(tgtHost):
hostname = tgtHost
ip = gethostbyname(tgtHost)
print '[+] the IP Addres for ' + hostname + ' is: ' + ip

def main():
parser = optparse.OptionParser('usage %prog -H' +\
'<target host>')
parser.add_option('-H', dest='tgtHost', type='string', \
help='specify target host')
(options, args) = parser.parse_args()
tgtHost = options.tgtHost
rlookup(tgtHost)

if __name__ == '__main__':
main()

No comments:

Post a Comment