Created
August 23, 2015 17:20
-
-
Save SimonWahlin/dbec1b97804fc4c993a0 to your computer and use it in GitHub Desktop.
My contribution to ScriptingGames 2015 August (http://powershell.org/wp/2015/08/01/august-2015-scripting-games-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
# Oneliner: | |
Invoke-RestMethod -Uri http://telize.com/geoip | Select-Object -Property longitude, latitude, continent_code, timezone | |
# Advanced function: | |
Function Get-GeoInformation | |
{ | |
<# | |
.Synopsis | |
Get geo information for current IP address or | |
any specified IP address. | |
.DESCRIPTION | |
Get geo information for current IP address or | |
any specified IP address. | |
Using web service http://telize.com/geoip to get | |
geo information. Requires internet connectivity. | |
.EXAMPLE | |
Get-GeoInformation | |
Get geo information for current IP address. | |
.EXAMPLE | |
Get-GeoInformation -IPAddress '56.86.48.9', '56.86.48.10' | |
Get geo information for IP addresses specified. | |
.EXAMPLE | |
'56.86.48.9', '56.86.48.10', '56.86.48.11' | Get-GeoInformation | |
Get geo information for IP addresses sent through pipeline. | |
.INPUTS | |
IPAddress | |
.OUTPUTS | |
PSCustomObject | |
#> | |
[cmdletbinding(ConfirmImpact='None')] | |
[OutputType([PSCustomObject])] | |
param( | |
# Gets geo information for specific ip addresses. The default is current IP. | |
[Parameter(ValueFromPipeline)] | |
[IPAddress[]] | |
$IPAddress | |
) | |
Process | |
{ | |
Try | |
{ | |
if($PSBoundParameters.ContainsKey('IPAddress')) | |
{ | |
Foreach($IP in $IPAddress) | |
{ | |
$URI = 'http://telize.com/geoip/{0}' -f $IP.IPAddressToString | |
Invoke-RestMethod -Uri $URI | |
} | |
} | |
else | |
{ | |
Invoke-RestMethod -Uri http://telize.com/geoip | |
} | |
} | |
Catch | |
{ | |
Throw | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment