3

There are a plethora of websites that will try to deduce your location from your IP address. For example: https://nordvpn.com/what-is-my-ip/.

This is handy for debugging VPNs - if I visit one of these sites and the location corresponds to the reported server location, rather than where I actually am, then I'm reasonably sure the VPN is working.

I'd like to be able to use a tool like this from the command line, where I can't operate a complicated web browser. Does such a tool exist?

For what it's worth, I am running Gentoo using OpenVPN, and my provider is Private Internet Access. But I hope that there's a reasonably cross-platform solution.

3
  • Does this answer your question? Get the external IP address in shell without dig in 2016?
    – muru
    Jun 30, 2021 at 22:46
  • @muru Doesn't seem so - they appear to only deal with IP addresses, but not location. I also get a different answer from the IP I'm sure of with the cloudflare solution suggested there (dig @1.1.1.1 TXT whoami.cloudflare.com +short), but I don't know why. Jun 30, 2021 at 22:51
  • If you are required to host this yourself, this functionality can be achieved by a small script on a public webserver. I have provided an example here.
    – Panki
    Jul 1, 2021 at 6:58

1 Answer 1

10

You can use ipinfo.io or ipstack.com services through curl:
curl --silent "https://ipinfo.io/ip"
similarly change ip to country to get your geographical location.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.