ip address?

maximilianscherr MaximilianScherr at T-Online.de
Fri Jan 25 20:01:59 EST 2002


thanks, but i think this also won't tell me my internet address, at 
least when i tried it just got my lan ip which is just 192.0.0.10 all 
the time.


--- In python-list at y..., "Joshua Muskovitz" <joshm at t...> wrote:
> "maximilianscherr" <MaximilianScherr at T...> wrote in message
> news:mailman.1012002740.18212.python-list at p...
> > 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 t...
> 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! =-----
> -- 
> http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list