Find my IP Address?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Find my IP Address?

Post by bogs » Thu Sep 07, 2017 7:42 pm

For a 4 year old thread, this actually peaked my interest, although I am unlikely to ever use this information. I mostly found out that without having your own server, it is (nearly) impossible for a client computer to get it's own external i.p. address as Richard points out.

If you do have a server, it becomes fairly easy, either through Lc, php, or the like. What is left for you to figure out is whether the server can be on the same network or not, at least none of the information I readily came across indicated one or the other.

And of course there are the less overpowering 3rd parties that were being asked to avoid, such as this one, which appears to be pretty nice in that it has a lot of options and it only returns text so you don't have to parse half the planet.

IF you are on a linux box, I found you could install dig (or similar) and query open.dns (which has since been aquired by Oracle (ewwww) . It makes me wonder if that would work with other dns solutions, I suspect it would.

All in all, pretty interesting stuff.
Image

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

Re: Find my IP Address?

Post by AxWald » Fri Sep 08, 2017 10:34 am

Hi,
FourthWorld wrote:The bigger question here is: why is the address needed?
There's quite many possibilities why you would want to know your external IP:
For checking the functionality of your DynDNS, for pinging/ portscanning yourself from the outside, for finding your clients data in the log on a remote server etc. etc.

Quite some services exist out there that offer this service - google "my IP" ;-)
But all of them cease to function as soon as I finally can remember their name, and nearly all of them require some parsing when queried via code.

So I usually have a button "Test connectivity" in any of my IN dependent programs. It answers the external IP that I get via a little "myip.php" script that resides besides the "index.html" on the customers server.
So I can get:
- my external IP
- knowledge if I have IN and
- knowledge if the server is up
all at once. Handy.

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]
?>
In LC I call a function:

Code: Select all

function INTest withTime
   --  put "myDomain.org/myip.php" into gName_IPURL
   if withTime then                      -- return IP & latency 
      put the millisecs into t1
      put url gName_IPURL into myIP
      put the millisecs - t1 into t2
      return myIP & CR & t2
   else                                       --  return IP only
      return url gName_IPURL
   end if
end INTest
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!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Find my IP Address?

Post by Thierry » Fri Sep 08, 2017 11:40 am

AxWald wrote:Hi,
There's quite many possibilities why you would want to know your external IP:
For checking the functionality of your DynDNS, for pinging/ portscanning yourself from the outside, for finding your clients data in the log on a remote server etc. etc.
Well said AxWald !

One way to do it without the need to install,
set up and manage your own server,
and all in a couple of minutes ... thanks LiveCode.

Code: Select all

on check_myIP
   if matchText(  URL "http://www.query-ip.com", \
         "(?ms)<input\s+class=.mdl-textfield__input.+?\svalue=.([\d.]+).\s+name" \
         , myIP \
   ) 
   then   answer "Your IP is: " & myIP
   else  answer "Sorry, doesn't work :("
end check_myIP
Disclaimer:
done in a couple of minutes with 1 test.
You have been warned!

Disclaimer2:
Of course, if the html of query-ip.com changes later on,
this script has to be update too.

Have fun too :)

Thierry
Last edited by Thierry on Sat Sep 09, 2017 9:23 am, edited 1 time in total.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

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

Re: Find my IP Address?

Post by FourthWorld » Fri Sep 08, 2017 4:02 pm

It seems I'm a less clear writer than I'd hoped. When I asked "why is the address needed?" I didn't mean to imply that no such need was possible. It's a big world; all things are possible. I'm merely interested in the use case which prompted this thread.

Being such an old thread we may never learn that, but it's precisely because we can imagine such a broad range of scenarios that choosing a good solution for Newbie4 requires us to consider his project's specific needs.

Moreover, what we've seen in the solutions offered here is that each of them requires a server, something the OP was hoping to avoid.

Even Thierry's most recent solution, useful as it is, relies on a server (query-ip.com). On the one hand, at least it's not a server one needs to maintain, but on the other hand it's not a sever one can maintain: as we've seen in the first suggestion in this thread of relying on a third-party service (qery.us), we have no guarantees about how long any third-party service will remain active and available.

For specialized intermediate-level admin tasks like those AxWald suggested (DynDNS, pen-testing, monitoring), there can be some good value in obtaining external IP address, but at that skill level it seems more likely one would just put a one-line PHP or LC Server script on an external server and be done with it.

The most common use case I've seen for requests about obtaining one's own external IP is P2P. But there are reasons most of the industry's interest in P2P peaked around the turn of the century, and since then things have been thriving around client-server clouds.

But I'm just guessing. Without input from Newbie4, there's no way to know whether his interest was in P2P, external monitoring, or something else.

At least in the interim we've collected a wide range of useful options in case anyone needs them.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sid
Posts: 15
Joined: Thu Dec 05, 2019 8:27 pm

Re: Find my IP Address?

Post by sid » Fri Dec 06, 2019 8:28 am

The webservice above doesn't work anymore for international IP addresses

this one here seems to:

put URL "(a p i .ipify . org" into" into globalIP

Note: I had to remove the htt... because of forum rules

returns just a simple IP address

Does anyone know a webservice like this that returns a user location if someone is using a windows machine. Android is simple , but a webservice will be great as a backup incase geolocation is switched off. Need it for security logs.

:D

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Find my IP Address?

Post by Klaus » Fri Dec 06, 2019 1:27 pm

Hi sid,

welcome to the forum!
Thank you for the link, very helpful: http://api.ipify.org


Best

Klaus

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Find my IP Address?

Post by Mark » Thu Jan 09, 2020 2:55 pm

http://economy-x-talk.com/ip.php has been up since 2005.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: Find my IP Address?

Post by FourthWorld » Thu Jan 09, 2020 4:32 pm

Mark wrote:
Thu Jan 09, 2020 2:55 pm
http://economy-x-talk.com/ip.php has been up since 2005.
Thanks Mark. Is there a tutorial there on how to obtain one's IP address from script?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Find my IP Address?

Post by Klaus » Thu Jan 09, 2020 5:55 pm

FourthWorld wrote:
Thu Jan 09, 2020 4:32 pm
Mark wrote:
Thu Jan 09, 2020 2:55 pm
http://economy-x-talk.com/ip.php has been up since 2005.
Thanks Mark. Is there a tutorial there on how to obtain one's IP address from script?
Sir? :shock:
Does:

Code: Select all

...
put URL("http://economy-x-talk.com/ip.php") into fld "my own IP address"
...
no more do the trick?

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

Re: Find my IP Address?

Post by FourthWorld » Thu Jan 09, 2020 5:57 pm

Thanks, Klaus. There are many such services around, it didn't occur to me that Mark was offering his as a scalable solution for everyone to use.

For those looking for a code example for making your own solution, see my earlier post in this very old thread:
https://forums.livecode.com/viewtopic.p ... 02#p157955
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”