Re: ifconfig in python

Discussion in 'Python' started by James Mills, Jan 20, 2009.

  1. James Mills

    James Mills Guest

    On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres <> wrote:
    > Is ther an easy way to get the resolved ip address of the machine a script
    > is running on? socket.gethostbyname(socket.gethostname) has only returned
    > the ip address of my loop back interface ... not very usefull.


    That's because your /etc/hosts resolves
    your hostname to 127.0.0.1 :)

    And no I know of no "easy" way cross
    platform way. Perhaps parsing the output
    of ifconfig itself ?

    cheers
    James
    James Mills, Jan 20, 2009
    #1
    1. Advertising

  2. James Mills

    Mark Wooding Guest

    "James Mills" <> writes:

    > On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres <> wrote:
    >> Is ther an easy way to get the resolved ip address of the machine a
    >> script is running on? socket.gethostbyname(socket.gethostname) has
    >> only returned the ip address of my loop back interface ... not very
    >> usefull.

    >
    > That's because your /etc/hosts resolves your hostname to 127.0.0.1 :)


    This just illustrates the real problem with the OP's question. The idea
    of `/the/ ... ip address of the machine' is simply ill-formed.

    An Internet host has at least two IP addresses -- one of them is
    127.0.0.1 -- and may have many more. The laptop I'm typing on right now
    has three; the server next door has four. Network interfaces may have
    multiple addresses associated with them (and hosts using the weak
    end-system model consider the addresses as referring to the host in
    general rather than a specific interface anyway), and several interfaces
    might have the same address.

    Sorry. Life's more complicated than you'd like it to be.

    -- [mdw]
    Mark Wooding, Jan 20, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. voger

    java ifconfig

    voger, Nov 8, 2005, in forum: Java
    Replies:
    19
    Views:
    1,546
    Roedy Green
    Nov 10, 2005
  2. Bart Van Loon

    portable Python ifconfig

    Bart Van Loon, Mar 3, 2007, in forum: Python
    Replies:
    6
    Views:
    2,796
    Bart Van Loon
    Mar 4, 2007
  3. Дамјан ГеоргиевÑки

    Re: ifconfig in python

    Дамјан ГеоргиевÑки, Jan 20, 2009, in forum: Python
    Replies:
    3
    Views:
    353
    Mark Wooding
    Jan 20, 2009
  4. bruce

    RE: ifconfig in python

    bruce, Jan 20, 2009, in forum: Python
    Replies:
    0
    Views:
    719
    bruce
    Jan 20, 2009
  5. bruce

    RE: ifconfig in python

    bruce, Jan 20, 2009, in forum: Python
    Replies:
    1
    Views:
    349
    Mark Wooding
    Jan 20, 2009
Loading...

Share This Page