Get-GeoIP.ps1
<#PSScriptInfo
.VERSION 1.0.2 .GUID 0b41e53b-62ea-4e72-b4fc-882c04c7b358 .AUTHOR PM091 .DESCRIPTION Get-GeoIP .COMPANYNAME pez863 .TAGS PSScript .PROJECTURI https://github.com/pm091/Get-GeoIP #> function Get-GeoIP { <# .Synopsis Resolve IPAddress Geo IP Location .Description This Function Queries The IP API With Supplied IPAdderess And Returns Geo IP Location .Parameter IPAddress IPAddressTo Be Resolved .Example Get-GeoIP -IPAddress 96.23.36.24 .Example $IP = Get-NetStat | select -ExpandProperty ForeignAddressIP | Where-Object {$_ -notlike '`['} Get-GeoIP -IPAddress $IP .Example $IP = (Get-NetTCPConnection).remoteaddress | Where-Object {$_ -notmatch '0.0.0.0|:'} Get-GeoIP -IPAddress $IP #> [CmdletBinding()] param( [Parameter (Mandatory = $true, ValueFromPipeline = $false)] [ValidatePattern("(?:(?:1\d\d|2[0-5][0-5]|2[0-4]\d|0?[1-9]\d|0?0?\d)\.){3}(?:1\d\d|2[0-5][0-5]|2[0-4]\d|0?[1-9]\d|0?0?\d)")] [string[]]$IPAddress ) begin { $CurrentIP = 0 } process { foreach ($IP in $IPAddress) { $CurrentIP++ Write-Progress -Activity "Resoving IPAddress: $IP" -Status "$CurrentIP of $($IPAddress.Count)" -PercentComplete (($CurrentIP / $IPAddress.Count) * 100) try { Write-Verbose 'Sending Request to http://ip-api.com/json/' Invoke-RestMethod -Method Get -Uri "http://ip-api.com/json/$IP" -ErrorAction SilentlyContinue | Foreach-object { [pscustomobject]@{ IPAddress = $IP Country = $_.Country CountryCode = $_.CountryCode Region = $_.Region RegionName = $_.RegionName City = $_.City 'Postal Code' = $_.Zip Org = $_.Org ISP = $_.ISP as = $_.as Query = $_.Query Lat = $_.Lat Lon = $_.Lon TimeZone = $_.TimeZone } } } catch { Write-Warning -Message "$IP : $_" } Start-Sleep -Seconds 1 } } end { } } |