Created
July 8, 2019 13:42
-
-
Save mattmcnabb/10ad57e38f0da5dc5075908ad41ec784 to your computer and use it in GitHub Desktop.
Get IP Address WhoIs Info
This file contains hidden or 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
function Get-JsonWhois | |
{ | |
[CmdletBinding(DefaultParameterSetName = "ip")] | |
param | |
( | |
[Parameter(Mandatory, ParameterSetName = "ip")] | |
[string] | |
$IPAddress, | |
[Parameter(Mandatory, ParameterSetName = "domain")] | |
[string] | |
$DomainName, | |
[Parameter(Mandatory)] | |
[string] | |
$ApiToken | |
) | |
$BaseUri = "https://api.jsonwhois.io/whois" | |
$Uri = switch ($PSCmdlet.ParameterSetName) | |
{ | |
"ip" | |
{ | |
"{0}/{1}?key={2}&ip_address=$IPAddress" -f $BaseUri, "ip", $ApiToken, $IPAddress | |
} | |
"domain" | |
{ | |
"{0}/{1}?key={2}&domain=$DomainName" -f $BaseUri, "domain", $ApiToken, $DomainName | |
} | |
} | |
Invoke-RestMethod -Uri $Uri | Select-Object -ExpandProperty Result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment