Geolocating Your IP on a Map

by Oct 6, 2016

As you have seen in previous tips, the Internet knows your IP address, and also where you are located. You can get the latitude and longitude of your current public Internet IP like this:

$ip = Invoke-RestMethod -Uri http://checkip.amazonaws.com/ 
$geo = Invoke-RestMethod -Uri "http://geoip.nekudo.com/api/$IP" 
$latitude = $geo.Location.Latitude
$longitude = $geo.Location.Longitude

"Lat $latitude Long $longitude"

If you’d like to see where that actually is, connect this information with Google Maps:

$ip = Invoke-RestMethod -Uri http://checkip.amazonaws.com/ 
$geo = Invoke-RestMethod -Uri "http://geoip.nekudo.com/api/$IP" 
$latitude = $geo.Location.Latitude
$longitude = $geo.Location.Longitude

$url = "https://www.google.com/maps/preview/@$latitude,$longitude,8z"
Start-Process -FilePath $url

This opens up a browser, navigates to Google Maps, and displays the location on a map. Fortunately, geolocating an IP address is still a fairly rough guess, at least publicly available geolocation data.

Twitter This Tip! ReTweet this Tip!