How Do You Find a Computer’s Geographic Location Using the Command Line?

how-do-you-find-a-computer-and-8217;s-geographic-location-using-the-command-line photo 1

There are many ways to learn the location of a computer from its IP address, but how do you go about it if you decide to use the command line to find the information? Today’s SuperUser Q&A post has some helpful suggestions to help a reader find the information he wants.

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

Screenshot courtesy of Paul Fenwick (Flickr).

The Question

SuperUser reader AlikElzin-kilaka wants to know how to find a computer’s IP address location using the command line:

How do I find a computer’s internet (IP address) location using the command line? Would I use curl or wget, for example?

How do you find a computer’s IP address location using the command line?

The Answer

SuperUser contributors AlikElzin-kilaka and Ben N have the answer for us. First up, AlikElzin-kilaka:

There is a service (IPInfo) that can provide the results. You can invoke it using curl, for example:

  • curl ipinfo.io

Result:

how-do-you-find-a-computer-and-8217;s-geographic-location-using-the-command-line photo 2

A specific IP’s info can also be requested:

  • curl ipinfo.io/216.58.194.46

Result:

how-do-you-find-a-computer-and-8217;s-geographic-location-using-the-command-line photo 3

Source: How to look up the geographic location of an IP address from the command line

Followed by the answer from Ben N:

Since the question does not specify an operating system, this is how to get that same information with PowerShell’s curl (actually an alias of Invoke-WebRequest):

  • (curl ipinfo.io).Content

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

  • curl ipinfo.io | ConvertFrom-Json

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

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

Note that the geographical information from this service is not super accurate, but it did locate me within 20 miles or so of my actual location and the ISP information seems to be reliable.


Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

Article How Do You Find a Computer’s Geographic Location Using the Command Line? compiled by Original article here

More stories

How to Send Large Files Over Email

Many email servers refuse to accept email attachments over 10MB in size. While attachment sizes haven’t kept up with the times, there are other easy ways to send someone large files over email.

If You Haven’t Tried a Mechanical Keyboard Yet, You’re Missing Out

Mechanical keyboards are all the rage these days. Hardcore gamers and long-haul coders alike are flocking away from traditional membrane-based keyboards in favor of their more clicky-clacky competition. If you still haven’t hopped on the bandwagon, here’s everything you need to know.

How to Stop Windows 10 From Asking You For Feedback

Windows 10 doesn’t just automatically collect information about your computer usage. It does do that, but it may also pop up from time to time and ask for feedback. Here’s how to disable any Windows Feedback pop-up notifications you may see.

How to Use the Belkin WeMo Insight Switch to Monitor Power Usage

Belkin has a diverse lineup of WeMo products, but its latest addition is the WeMo Insight Switch. It not only allows you to turn appliances on and off from your smartphone, but it also monitors power usage and provides estimates on how much you’re spending by having that space heater plugged in.

How to Reboot or Factory Reset Your Google Chromecast

Google changed the device-to-TV scene with Chromecast, but as with all technology, it can have problems. At some point, you may need to reboot or factory reset your Chromecast.  While these options are slightly hidden to prevent an accidental reset, it’s a straightforward and simple process.