ipify is a very useful web service (an API) that promises to always be available to attend requests, letting us know the public (or external) IP address we are using to connect to Internet. We can get this small piece of information as pure Text or in JSON or XML formats.
This post was updated in 2021 to using Xojo’s API 2.0.
There are plenty of times when your Xojo apps might need to know what the public or external IP address in use is, and for that there are a lot of web sites or services that you can use from Xojo. Nevertheless, I found ipify to be the simplest and easiest to use, plus it is highly available due to being hosted by Heroku. That means, for example, that if half the Internet is down…you still can be confident to reach the ipify service in order to get the information.
Using ipify from a Xojo desktop apps is as simple as using this code:
Dim request as New HTTPSSocket Dim s as String = request.get("https://api.ipify.org",10)
But sometimes we need additional information, for example knowing if the IP address has changed over time, or simply checking periodically for IP address changes. And that is something that you can find in the OpenSource project ipify for Xojo available in this repository from GitHub.
ipify for Xojo is designed as a Singleton class, what means that you even don’t need to instatiate it in order to get the current IP address, know if the IP has changed over time, or even instruct the class to periodically check for the IP address, notifying the registered object every time with the current IP address in use and if it is the same or has changed from the last checking.
Javier Rodriguez has been the Xojo Spanish Evangelist since 2008, he’s also a Developer, Consultant and Trainer who has be using Xojo since 1998. He manages AprendeXojo.com and is the developer behind the GuancheMOS plug-in for Xojo Developers and the Snippery app, among others.