Determining External IP Address.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Determining External IP Address.
Hi Guys!!
This question is the same as the subject. Is there a way to determine the external IP address?
Many Thanks,
Googie.
This question is the same as the subject. Is there a way to determine the external IP address?
Many Thanks,
Googie.
-
- VIP Livecode Opensource Backer
- Posts: 9850
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Determining External IP Address.
The easiest way is to put an LC Server script on your server that returns $REMOTE_ADDR.
What will you be doing with it?
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Determining External IP Address.
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.
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.
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"?):
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!
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]
?>
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!
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!
-
- Posts: 57
- Joined: Mon Oct 28, 2013 1:23 pm
- Location: Dresden, Germany
Re: Determining External IP Address.
Eayiest way with LC server (which can be rented < 4 $ monthly on www.hostm.com) is this script:
The output is the ip of the client.
Cheers,
Torsten
Code: Select all
<?lc
put $_SERVER["REMOTE_ADDR"]
?>
Cheers,
Torsten
-
- Posts: 722
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Determining External IP Address.
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
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":"" into tPartBefore
put ""," into tPartAfter
GetPartOfString tURLData, tPartBefore, tPartAfter, tResult
put tResult into tIPAdress
--
put "country_name":"" into tPartBefore
put ""," 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":"" into tPartBefore
# put "country_name":"" into tPartBefore
# put "time_zone":"" into tPartBefore
# put "region_name":"" into tPartBefore
# put "continent_code":"" into tPartBefore
# put "continent_name":"" into tPartBefore
# put "city_name":"" into tPartBefore
# and more, put the url in a field, copy the data from the field to word and start looking for interesting strings.