Get your Public IP and Geographic Data with PowerShell


Always fascinated by what can be done very tersely with PowerShell.

I saw an interesting tip on that gives the geopraphic info on a given public IP. They had a post I dug up a couple years back that determines your public IP dynamically, so I connected the Lego blocks… here is a script that determines your public IP and tells you where you are, using a web page and a REST API.

[codesyntax lang=”powershell”]

#Determine Public IP Dynamically
$ipaddress = (Invoke-WebRequest '' -UseBasicParsing).Content
$infoService = "$ipaddress"
#Get Geographic Data based on my IP
$geoip = Invoke-RestMethod -Method Get -URI $infoService

#As a One-Liner
(Invoke-RestMethod -Method Get -URI "$(Invoke-WebRequest '' -UseBasicParsing)").Response






All Rights Reserved Theme by 404 THEME.