ip address?

Joshua Muskovitz joshm at taconic.net
Fri Jan 25 19:54:04 EST 2002


"maximilianscherr" <MaximilianScherr at T-Online.de> wrote in message
news:mailman.1012002740.18212.python-list at python.org...
> how can i get the internet ip address of my connected pc?

###################################################################

# Handy methods for handling hostnames and IP addresses
import socket

def GetLocalHostname():
    return socket.gethostname()

def GetIPstring(hostname = None):
    # This will return a dotted decimal string (ie, "12.34.56.78") for the
specified hostname.
    # If no host is specified, the local host is assumed.
    if hostname == None:
        hostname = GetLocalHostname()
    try:
        return socket.gethostbyname(hostname)
    except:
        return ""

def GetIPint(hostname = None):
    # This will return an int which contains the IP address (ie, 0x78563412)
for the specified hostname.
    # note that DDD is the MSB and AAA is the LSB here!
    a,b,c,d = map(string.atoi,string.split(GetIPstring(hostname),"."))
    return a | b<<8 | c<<16 | d<<24

###################################################################


--
# Joshua Muskovitz
# joshm at taconic.net
def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"])
lyyrs('Hire me!  I need the work!')




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list