I wanted a simple, free, no-limits way of finding out my own public IP. I also wanted a way to use it in my Java code so I wouldn’t need a really complex, and non-guaranteed way of finding the IP. I can’t believe the number of times I’ve searched for “How to get my public IP in Java?” or several variations of the same and I was tired of it.

I wrote a simple server which has one endpoint which returns the IP address of the called. It’s a no-frills service currently hosted here: https://caffinc.com/myip

You can find the code for this service here or you could download a pre-compiled jar which can be run on your server here.

I would like to say that I don’t intentionally log any information on my server apart from whatever the server needs to ensure there’s no DDOS attacks on it. Please play nice with the service, I don’t want to have to ban anyone, or to have my service revoked because someone abused the system.

You can use the code from my Gist in your Java code: