Reputation: 45
I am using sprint boot. I want to check what is current location where that spring boot application is running. I figured out making use of environment variable on spring but no idea on how to get the location.
The environment variable should send the location of current application running as it could be deployed in various locations ex: U.S/India.
Thanks in advance
Upvotes: 2
Views: 391
Reputation: 4592
In my opinion solution will be in 2 steps:
Step 1 : Get the public IP of the machine where code is being executed.
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
String ip = in.readLine(); // Public IP of machine
Step 2 : Get the location by that IP address
For that you can use MaxMind GeoIP Lite database as mentioned in here in another answer or article.
Upvotes: 1