Created
August 4, 2015 15:22
-
-
Save thomasrayner/43d4697b64cc797fa8a9 to your computer and use it in GitHub Desktop.
2015-August Scripting Puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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