ifconfig in python
mdw at distorted.org.uk
Tue Jan 20 03:50:28 CET 2009
"James Mills" <prologic at shortcircuit.net.au> writes:
> On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres <vivacarlie at gmail.com> 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
> 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.
More information about the Python-list