4

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.

preferred_anon
  • 329
  • 4
  • 12
  • Does this answer your question? [Get the external IP address in shell without dig in 2016?](https://unix.stackexchange.com/questions/254328/get-the-external-ip-address-in-shell-without-dig-in-2016) – muru Jun 30 '21 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. – preferred_anon Jun 30 '21 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.](https://lab.theresno.cloud/panki/remotekit/-/raw/master/ip.py) – Panki Jul 01 '21 at 06:58

1 Answers1

12

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.

Zeta.Investigator
  • 880
  • 1
  • 7
  • 25