Getting IP Address of Machine that is Currently Running the Stack

Dave dave at looktowindward.com
Thu Oct 26 11:03:13 EDT 2006


Hi,

Thanks a lot, that worked great, for anyone that is interested, here  
is a function to return the local IP address:


------------------------------------------------------------------
--
--  Get the Local IP Address of this Machine
--
------------------------------------------------------------------
function GetLocalHostIPAddress
   local myIPAddress
   local myHostAddress

   put "255.255.255.255:6000" into myIPAddress
   open datagram socket to myIPAddress
   put the hostAddress of myIPAddress into myHostAddress
   close  socket myIPAddress

   return myHostAddress
end GetLocalHostIPAddress


------------------------------------------------------------------
--
--  Test it on a Button
--
------------------------------------------------------------------
on mouseUp
  put GetLocalHostIPAddress()
end mouseUp


Thanks again
Dave

On 25 Oct 2006, at 20:41, Dar Scott wrote:

>
> 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
> **************************************
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list