Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Created July 8, 2019 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmcnabb/10ad57e38f0da5dc5075908ad41ec784 to your computer and use it in GitHub Desktop.
Save mattmcnabb/10ad57e38f0da5dc5075908ad41ec784 to your computer and use it in GitHub Desktop.
Get IP Address WhoIs Info
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