How to get IP address
John Abel
john.abel at pa.press.net
Mon Mar 3 04:02:26 EST 2003
Opps, too quick :)
OK. Running
socket.gethostbyaddr( socket.gethostname() )
will return all your IP's, internal and external. For example:
('hallows', [], ['101.101.101.102', '10.253.1.118'])
is the output of my own, multi-homed machine. "Hallows" is my
hostname/computer name, with the 2nd list showing the IP's from my two
devices ( ethernet, and modem). As a matter of interest, what is the
output of gethostbyaddr? It should look something like:
('arwen', [], ['192.168.1.1', 'x.x.x.x'])
Nagy László Zsolt wrote:
>> I'm still lost :) How are you getting the hostname dynamically? The
>> hostname is assigned during the install of the OS. Changing this (on
>> windows) will require a reboot. Where I work, every machine is DHCP,
>> but they all have hostnames assigned to them when windows is installed.
>
>
>
> This machine is a firewall. One side is connected to the internal
> network. It has address 192.168.1.1 and a fixed hostname 'arwen'.
> The other side is an ADSL connection. I get the IP address every time
> I connect. That IP address has one or more DNS names assigned.
> This computer is a multi-hosted machine. It has more than one IP
> addresses. You can see that gethostbyname('arwen') returns '192.168.1.1'
> because the host 'arwen' is 192.168.1.1 in my local network. But I
> need to determine the external IP (that connects directly to Internet).
>
> In windows, you can set the computer name which is not the same. It is
> a name of computer in Microsoft Windows Network.
> I hope this helps.
>
> Laci 1.0
More information about the Python-list
mailing list