IP address

Beej beej at beej.us
Sun Jan 28 21:50:52 EST 2007


On Jan 28, 2:26 am, Klaus Alexander Seistrup <k... at seistrup.dk> wrote:
> Scripter47 wrote:
> > How do i get my ip address?
>
> > in cmd.exe i just type "ipconfig" then it prints:
> >       ...
> >       IP-address . . . . . . . . . . . . . . . . . : 192.168.1.10
> >       ...
> > how can i do that in python??#v+
>
> python -c 'import re, urllib; print re.findall("<title>Your IP: (.+?)</title>", urllib.urlopen("http://myip.dk/").read())[0]'

This is extremely unlikely to return 192.168.1.10. :-)

(It will give you the address of your firewall or whatever is your 
gateway to the outside world...  which is a cool thing to know, but 
I'm not sure it's what the op's after.)

-Beej




More information about the Python-list mailing list