Obtaining the public IP of a computer...

David C. davidocoker at gmail.com
Wed Feb 9 02:51:23 EST 2011

On Tue, Feb 8, 2011 at 8:43 PM, Paul Dupuis <paul at researchware.com> wrote:
> I am looking for ideas/suggestion on how, in live code, to obtain the public
> IP address of the computer a LiveCode standalone is running on.
> hostName() returns the name of the computer.
> hostNameToAddress(hostName()) return the IP address, such as,
> but (as in this case) if the system is behind a NAT device, like a typical
> internet router, all you get a is local address
> DNSservers() can get you the IPs of the computers DNS servers
> I can find no function to get the gateway address - i.e. the address of the
> router the computer is connected to.
> Is the only approach to go after the real IP is to do so through a shell
> command? Or is there some clever LiveCode function I am missing?
> --
> Paul Dupuis
> Cofounder
> Researchware, Inc.
> http://www.researchware.com/

Hello Paul,
If you have access to a reliable web server that will run PHP, then
you can use this code:


    if (getenv(HTTP_X_FORWARDED_FOR)) {
        $pipaddress = getenv(HTTP_X_FORWARDED_FOR);
        $ipaddress = getenv(REMOTE_ADDR);
echo "Your Proxy IPaddress is : ".$pipaddress. "(via $ipaddress)" ;
    } else {
        $ipaddress = getenv(REMOTE_ADDR);
        echo "$ipaddress";

Name it something like "get_ip.php" and drop it in the folder location
of your choice, then use livecode to parse the results:

on mouseUp
   get URL "http://www.mydomain.com/foldername/get_ip.php"
   put it into tIPaddy
   answer tIPaddy
end mouseUp

That will work in a pinch, I believe.

Best regards,
David C.

More information about the Use-livecode mailing list