IPGeolocation.psm1
function Get-IPGeolocation { <# .SYNOPSIS Get IP information from IPAPI.co .DESCRIPTION This command pulls information about an IP address from IPAPI.co. The API feeds back JSON data. .PARAMETER IPAddress Enter an IP address, such as 1.1.1.1 .PARAMETER AllInfo Use this parameter to return all IP information .EXAMPLE Get-IPGeolocation -IPAddress 1.1.1.1 -AllInfo .NOTES #> param ( [Parameter(Mandatory = $true)] [System.Net.IPAddress] $IPAddress, [parameter(Mandatory = $false)] [Switch] $AllInfo ) $LookupRequest = Invoke-RestMethod -Method Get -Uri https://ipapi.co/$IPAddress/json/ If (($AllInfo)) { $LookupRequest } Else { [PSCustomObject]@{ IP = $LookupRequest.ip Country = $LookupRequest.country_name City = $LookupRequest.city Org = $LookupRequest.org } } } function Get-URLIPGeolocation { <# .SYNOPSIS Gets the IP address the URL resolves to, then gets the information on those IP addresses from IPAPI. .DESCRIPTION This command gets the IP addresses that the URL resolves to and then gets the IP information from IPAPI.co. The API feeds back JSON data. .PARAMETER URL Enter an url, such as google.co.uk .EXAMPLE Get-URlIPGeolocation -URL google.co.uk .NOTES #> param ( # Parameter help description [Parameter(Mandatory = $true)] [String] $URL, [parameter(Mandatory = $false)] [Switch] $AllInfo ) $DNS = Resolve-DnsName $URL $OutArray = @() foreach ($IP in $DNS.IpAddress) { $LookupRequest = Invoke-RestMethod -Method Get -Uri https://ipapi.co/$IP/json/ if (($AllInfo)) { $LookupRequest } Else { $LookupResults = [PSCustomObject]@{ IP = $LookupRequest.ip URL = $URL Country = $LookupRequest.country_name City = $LookupRequest.city Org = $LookupRequest.org } $OutArray += $LookupResults } $OutArray } } |