Reverse NS Lookup

Lokie anthony at lokie.co.uk
Sun Oct 22 14:15:39 EDT 2000


"Simon Faulkner" <News at Titanic.co.uk> wrote in message
news:km96vs8e6fppc78i072s3isdvrvntrh02t at 4ax.com...
> How do I find the domain name of an IP address?
>
> I have the IP address from os.environ["REMOTE_ADDR"] and I want to
> store the domain name in a database
>
> Simon
> Simon Faulkner

Not the best code to do the job, but hopefully should give you a good
starting point.

import socket

def ips:
    if os.environ.has_key('REMOTE_ADDR'):
        user = os.environ['REMOTE_ADDR']
        try:
            host, alias, ips = socket.gethostbyaddr(user)
            if host!="":
                user = host
        except socket.error, msg:
            pass
    else:
        user = "Local machine"
    return(user)


--
Anthony McDonald






More information about the Python-list mailing list