Skip to content

Instantly share code, notes, and snippets.

@thomasrayner
Created August 4, 2015 15:22
Show Gist options
  • Save thomasrayner/43d4697b64cc797fa8a9 to your computer and use it in GitHub Desktop.
Save thomasrayner/43d4697b64cc797fa8a9 to your computer and use it in GitHub Desktop.
2015-August Scripting Puzzle
#One-liner
Invoke-WebRequest http://www.telize.com/geoip | ConvertFrom-Json | Format-Table Longitude,Latitude,Continent_Code,Timezone -AutoSize
#Function
function Get-GeoIP
{
param
(
[array]$Attributes = '*',
[IPAddress]$IP
)
Try
{
if ($IP) { Invoke-WebRequest "http://www.telize.com/geoip/$IP" | ConvertFrom-Json | Select-Object $Attributes }
else { Invoke-WebRequest 'http://www.telize.com/geoip' | ConvertFrom-Json | Select-Object $Attributes }
}
Catch [Exception]
{
throw $_.Exception.Message
}
}
#Another JSON endpoint
Invoke-WebRequest 'http://headers.jsontest.com/' | ConvertFrom-Json | Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment