ip address?

Joshua Muskovitz joshm at taconic.net
Fri Jan 25 20:59:08 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 a DOS window, run winipcfg (win98) or ipconfig /all (win2k) and see what
it tells you.  If you have *multiple* IP addresses (one for your dial-up and
one for your lan, maybe?), then socket.gethostname() will return *one* of
them, but it could be either of them.  This is one of the nastier parts of
TCP, and has nothing to do with Python.

At the python command line, try this:

import socket
hostname = socket.gethostname()
addresses = socket.getaddrinfo(hostname, None)
ips = [x[4][0] for x in addresses]

This should give you all of the IP addresses for your machine.  It's your
problem to figure out which one is for your dialup provider.  Don't assume
it'll always be the same index into this list.

--
# 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