IP address of current computer....

Dar Scott dsc at swcp.com
Fri Dec 8 15:56:15 EST 2006


On Dec 8, 2006, at 1:05 PM, David Bovill wrote:

> Is there a simple way of obtaining the IP address of the current  
> computer?

Yes.



Oh, you want to know what it is?  Since you say "the" IP address, I  
assume you are expecting a single address.

Sarah mentioned this one and probably got it from someone who was  
perhaps inspired by my comments:

function getLocalIPAddress
  put "255.255.255.255:6000" into tCheckAddress
  open datagram socket to tCheckAddress
  put the hostAddress of tCheckAddress into tMyIP
  close socket tCheckAddress
  return tMyIP
end getLocalIPAddress

A bug was introduced into OS X that causes an error if you try to  
write to a broadcast address, but that is not be needed.

In special cases, a computer might have multiple IP addresses, as in  
the case of a firewall or a computer using dialup and a LAN at the  
same time.  If you have multiple IP addresses on the computer, you  
can get the one that would be used to route to some address by using  
that address instead of 255.255.255.255, the broadcast address.  For  
example, you can get the one for Internet by using a non private  
Internet address.  Alternately, if your DHCP server's private IP  
address is known, you can use that to get to get the private IP address.

The broadcast will get you the "primary" IP address, whatever that  
means.

The ability to get the hostAddress was fixed on OS X at some point so  
this won't work in old versions.

This does no communication.  It is not intrusive.  You can use some  
IP address without even touching the associated computer.  That  
computer and your routers do not even have to be up.

Dar




More information about the Use-livecode mailing list