Page 1 of 1

Determining External IP Address.

Posted: Thu Jan 14, 2021 8:34 am
by Googie85
Hi Guys!!

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

Many Thanks,

Googie.

Re: Determining External IP Address.

Posted: Thu Jan 14, 2021 8:40 am
by FourthWorld
The easiest way is to put an LC Server script on your server that returns $REMOTE_ADDR.

What will you be doing with it?

Re: Determining External IP Address.

Posted: Thu Jan 14, 2021 8:52 am
by Googie85
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.

Re: Determining External IP Address.

Posted: Thu Jan 14, 2021 9:57 am
by AxWald
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!

Re: Determining External IP Address.

Posted: Fri May 14, 2021 3:58 pm
by TorstenHolmer
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

Re: Determining External IP Address.

Posted: Wed Nov 17, 2021 10:28 am
by mrcoollion
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.