Determining External IP Address.

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 144
Joined: Tue Aug 05, 2014 10:07 am

Determining External IP Address.

Post by Googie85 » Thu Jan 14, 2021 8:34 am

Hi Guys!!

This question is the same as the subject. Is there a way to determine the external IP address?

Many Thanks,

Googie.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8336
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Determining External IP Address.

Post by FourthWorld » Thu Jan 14, 2021 8:40 am

The easiest way is to put an LC Server script on your server that returns $REMOTE_ADDR.

What will you be doing with it?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Googie85
Posts: 144
Joined: Tue Aug 05, 2014 10:07 am

Re: Determining External IP Address.

Post by Googie85 » Thu Jan 14, 2021 8:52 am

I have developed a Paper, Rock, Scissors multiplayer game for Android. The client (on Android device) gets an IP address from a website and then connects to that IP address which is the server (Windows).

I wanted to check the external IP address with the saved IP address on the website and if it changes (my IP address changes every 48 hours), update the IP address on the web server via FTP when it changes, so that the website IP address will always be updated.

I'm not sure if I explained it in the best way, lol!

Many Thanks,

Googie.

AxWald
Posts: 478
Joined: Thu Mar 06, 2014 2:57 pm

Re: Determining External IP Address.

Post by AxWald » Thu Jan 14, 2021 9:57 am

Just to get it right:
It's the IP of the "server (Windows)", that your "client (Android)" should retrieve from a "web server (where you have FTP & a site)"?

The easiest way to achieve this to use DynDNS.
Check the router your Win server is behind - most routers have this feature. It works like this: Every time the external router IP changes the router notifies a service of the new number. And the service provides a URL that resolves to this IP.
Such a service (DynDNS) is available in quite same web server packages; there are some free services available, too (search: "free dyndns")
If it's working, you have a URL like "myserver.ddns.com" that always resolves to the current public IP of your "servers (Windows)" router. Add a port forwarding, Bingo.

Or you drop a little php script on the server ("myip.php"?):

Code: Select all

<?PHP
function getUserIP()
{
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];
    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }
    return $ip;
}
$user_ip = getUserIP();
echo $user_ip; // Output IP address [Ex: 177.87.193.134]
?>
This responds with the public IP of whatever calls it. Call it from the "server (Windows)", store the IP somewhere on the web server where the "client (Android)" can find it. Have your port forwarding, Bingo.

For sure, a LC server can do this, too. But it can be a bit cumbersome to set one up ;-)

I'd use DynDNS. Once established it works reliably & requires zero further action.

Have fun!
Livecode programming until the cat hits the fan ...

Post Reply

Return to “Windows”