IP address
Colin J. Williams
cjw at sympatico.ca
Sun Jan 28 08:28:32 EST 2007
Klaus Alexander Seistrup 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]'
>
> #v-
>
> Cheers,
>
Klaus,
Your one-liner doesn't work for me, with Windows XP, but the following
does, within Python.
*** Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32. ***
>>> import re, urllib; print re.findall("<title>Your IP:
(.+?)</title>", urllib.urlopen("http://myip.dk/").read())[0]
69.157.68.189
>>>
Colin W.
More information about the Python-list
mailing list