Python script for ip to hostname lookup
Question: I have never attempted to create a script in my entire life but I've come
across an issue where I would require a script (preferably Python) to perform
lookups. I have a system that actively monitors web and ftp traffic and I'm
able to get the sender IP address (typically the web proxy) but the proxies
are not passing credentials at this time.

I'd like to create a script that takes the sender-ip address, queries our
internal DNS server, and provides me with the hostname of the machine real
time. At that point, I would be able to take the response from DNS and perform
a secondary LDAP query to return additional attributes but I'm stuck on step
one.

I apologize if this is a very simple script but I've been looking and
unfortunately my background is not in scripting, so this is all very new to
me. Please let me know if you require any additional info.

Thanks!


Answer: 
    Python 3.3.1 (default, Apr 17 2013, 22:30:32) 
    [GCC 4.7.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import socket
    >>> socket.gethostbyaddr('74.125.225.35')
    ('ord08s06-in-f3.1e100.net', [], ['74.125.225.35'])
    >>> socket.gethostbyaddr('74.125.225.35')[0]
    'ord08s06-in-f3.1e100.net'
    

Call the python script from whatever app you have that acquires the connecting
IP address and pass the IP as a command line parameter.

