Use PowerShell to Get GeoLocation of a Computer’s Public IP

Method 1:

Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content)

Method 2:

function getIPGeolocation($ipAddress) {

$request = Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$ipAddress"

[PSCustomObject]@{
IP = $request.query
City = $request.city
Country = $request.country
Isp = $request.isp
}
}

$thisPublicIP=(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
getIPGeolocation $thisPublicIP

Leave a Reply

Your email address will not be published. Required fields are marked *