2

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.