Skip to content

Instantly share code, notes, and snippets.

@derekantrican
Created October 17, 2022 20:47
Show Gist options
  • Save derekantrican/53c77e49973bae654e88686599c04ef8 to your computer and use it in GitHub Desktop.
Save derekantrican/53c77e49973bae654e88686599c04ef8 to your computer and use it in GitHub Desktop.
An example to call the NameCheap API via powershell (and parse the result)
# This is just an example for the Get Hosts endpoint
# docs: https://www.namecheap.com/support/api/methods/domains-dns/get-hosts/
function GetNamecheapTarget
{
param
(
[string]$username,
[string]$apiKey,
[string]$domain,
[string]$domainHost,
[string]$clientIp
)
$command = 'namecheap.domains.dns.getHosts'
$response = Invoke-WebRequest -uri "https://api.namecheap.com/xml.response?ApiUser=$username&ApiKey=$apiKey&UserName=$username&ClientIp=$clientIp&Command=$command&SLD=$domain&TLD=com"
return (([xml]$response.Content).ApiResponse.CommandResponse.DomainDNSGetHostsResult.host | Where {$_.Name -eq $domainHost}).Address
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment