Clean way to get one's network IP address?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Wed Nov 21 17:34:16 EST 2007


On Wed, 21 Nov 2007 12:00:52 -0500, Joe Riopel wrote:

> On Nov 21, 2007 10:15 AM, Gilles Ganault <nospam at nospam.com> wrote:
>> I know about socket.gethostbyname, but this relies on what's in
>> /etc/hosts, and I'd rather have a more independent solution.
> 
> I might be missing something in your question, but on a Windows XP
> machine, I can get the IP address of my machine using:
>>>> from socket import gethostname, gethostbyname
>>>> gethostbyname(gethostname())
> '192.168.0.11'
>>>>


Just out of curiosity, what part of the Original Poster's comment that he 
already knew about socket.gethostbyname did you not understand?



-- 
Steven
who seems to be making a lot of snarky comments lately.



More information about the Python-list mailing list