Determining External IP Address.

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 169
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: 8901
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Googie85
Posts: 169
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: 578
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!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

TorstenHolmer
Posts: 40
Joined: Mon Oct 28, 2013 1:23 pm
Location: Dresden, Germany

Re: Determining External IP Address.

Post by TorstenHolmer » Fri May 14, 2021 3:58 pm

Eayiest way with LC server (which can be rented < 4 $ monthly on www.hostm.com) is this script:

Code: Select all

<?lc
put  $_SERVER["REMOTE_ADDR"]
?> 
The output is the ip of the client.

Cheers,
Torsten

mrcoollion
Posts: 624
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Determining External IP Address.

Post by mrcoollion » Wed Nov 17, 2021 10:28 am

You can also use a website like https://ipleak.net/ and get the information from it.
See code below. Paste the code in a Button, run it, and it should give you an answer on IP address and Country.

Regards,

Paul

Code: Select all

on mouseup
   put "https://ipleak.net/" into tReqURL
   put url tReqURL into tURLData
   --
   put "ip&quot;:&quot;" into tPartBefore
   put "&quot;," into tPartAfter
   GetPartOfString tURLData, tPartBefore, tPartAfter, tResult
   put tResult into tIPAdress
   --
   put "country_name&quot;:&quot;" into tPartBefore
   put "&quot;," into tPartAfter
   GetPartOfString tURLData, tPartBefore, tPartAfter, tResult
   put tResult into tCountryName
   --
   answer "IP Adress is:"&&tIPAdress&CR&"Country Name is:"&&tCountryName
end mouseup

command GetPartOfString tString, tPartBefore, tPartAfter @tResult // Part before must be unique
   put the length of tPartBefore into tL_StringToFind1
   put offset(tPartBefore,tString) into tStringP_Pos1
   put tString into tString_Data
   delete char 1 to (tStringP_Pos1+tL_StringToFind1-1) of tString_Data
   put offset(tPartAfter,tString_Data) into tString_Pos2
   put char 1 to (tString_Pos2-1) of tString_Data into tResult 
end GetPartOfString

# Strings you can use to find the information you are looking for
# put "ip&quot;:&quot;" into  tPartBefore
# put "country_name&quot;:&quot;" into  tPartBefore
# put "time_zone&quot;:&quot;" into  tPartBefore
# put "region_name&quot;:&quot;" into  tPartBefore
# put "continent_code&quot;:&quot;" into  tPartBefore
# put "continent_name&quot;:&quot;" into  tPartBefore
# put "city_name&quot;:&quot;" into  tPartBefore
# and more, put the url in a field, copy the data from the field to word and start looking for interesting strings.

Post Reply

Return to “Windows”