Getting IP Address of Machine that is Currently Running the Stack

Dar Scott dsc at swcp.com
Wed Oct 25 15:41:37 EDT 2006


On Oct 25, 2006, at 7:09 AM, Dave wrote:

> How can I get the IP address of the machine that a stack is running  
> on?

Open a datagram socket to a legal IP address.  That does not have to  
be assigned.  Then get the hostAddress of that socket.  Then close  
it.  The hostAddress will be what you want.

If the machine has more than one IP address, the address will be the  
one that would be used in trying to make the connection.  For  
example, on a firewall, the machine might have both a public IP  
address for one adaptor and a private IP address for the LAN on  
another adaptor.  Also, a single Ethernet LAN might have more than  
one IP address assigned to an adaptor on a machine (I use this for  
addressing both my network and instruments that come with a fixed IP  
address).  And then there are dialups and VPNs and...

The cool part about the datagram method is that it is not intrusive.   
It does not try to do anything on the net.

If you want the IP address of the default adaptor, try  
"255.255.255.255".  This does not always work; I forgot the constraints.

This method would not work at one time on OS X, but that was fixed.

Dar

--
**************************************
Dar Scott
Dar Scott Consulting  and  Dar's Lab
8637 Horacio Place NE
Albuquerque, NM 87111

Lab, office, home:  +1 505 299 9497
Fax:                call above first
Skype:              ask

http://www.swcp.com/dsc
dsc at swcp.com

Computer programming
**************************************





More information about the Use-livecode mailing list