How to get a computer's internet (IP address) location using command line?

For example, using curl or wget?

  • 4
    Could you specify what an "internet location" is? – Carsten S Apr 16 '16 at 14:27
  • The IP's address location. Adding to the questions... – AlikElzin-kilaka Apr 17 '16 at 6:48

There's a service providing this: ipinfo.io.

You can invoke it using curl. Example:

curl ipinfo.io


  "ip": "...",
  "hostname": "...",
  "city": "...",
  "region": "...",
  "country": "...",
  "loc": "...,...",
  "org": "..."

A specific IP's info can also be requested: curl ipinfo.io/

  "ip": "",
  "hostname": "dfw25s12-in-f14.1e100.net",
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.4192,-122.0574",
  "org": "AS15169 Google Inc.",
  "postal": "94043"

Source: http://xmodulo.com/geographic-location-ip-address-command-line.html

| improve this answer | |
  • 3
    Please note this service does not provide an accurate location. 50km wrong for me. – DavidPostill Apr 14 '16 at 8:20
  • 1
    I've no idea how it works. I'm currently on mobile internet. Google maps manages to locate me perfectly well. – DavidPostill Apr 14 '16 at 8:29
  • 1
    The curl command above just goes to a service without providing anything private. ipinfo.io has almost only the source IP to use to pin point the location and get data. – AlikElzin-kilaka Apr 14 '16 at 8:36
  • 2
    geoip is notoriously inaccurate... I can be either in Idaho, Minnesota or Oregon depending on the DHCP netblock of the day. – Fiasco Labs Apr 17 '16 at 3:51
  • 2
    @DavidPostill Google Maps uses GPS to position you on the map, it's pretty accurate. Geolocation by IP address usually gets region right. – Alexey Ivanov Apr 17 '16 at 10:42

Since the question doesn't specify an OS, this is how to get that same information with PowerShell's curl (actually an alias of Invoke-WebRequest):

(curl ipinfo.io).Content

That produces a JSON string. To get the object that JSON represents, use ConvertFrom-Json:

curl ipinfo.io | ConvertFrom-Json

Since that's a PowerShell object, you can easily get specific fields from it. For example, this command gets just the external IP as a string:

(curl ipinfo.io | ConvertFrom-Json).ip

Note that the geographical information from this service isn't super accurate, but it did locate me within 20 miles or so. The ISP information seems to be reliable.

| improve this answer | |

You can also use from PowerShell:

Invoke-RestMethod http://ipinfo.io/json

The command output will already give us the location in JSON

Extracted from: https://www.sysadmit.com/2019/01/windows-saber-ip-publica-PowerShell.html

| improve this answer | |

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.