Last active
November 23, 2022 10:28
-
-
Save matt40k/03410719493279800d642134ae94cb2e to your computer and use it in GitHub Desktop.
Uses DNS over HTTPS endpoint to lookup A records - PowerShell
This file contains 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
$domain = 'cloudflare.com' | |
$url = 'https://cloudflare-dns.com/dns-query?name='+$domain+'&type=A'; | |
$header = @{"accept"="application/dns-json"} | |
$response = (Invoke-WebRequest -Uri $url -Headers $header -UseBasicParsing).Content | |
$r = [System.Text.Encoding]::UTF8.GetString($response) | ConvertFrom-Json | |
$r | |
foreach ($item in $r.Answer) | |
{ | |
Write-Host $item | |
} |
This file contains 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
$domain = 'google.com' | |
$url = 'https://dns.google.com/resolve?name='+$domain + '&type=A'; | |
$r = (Invoke-WebRequest -Uri $url -UseBasicParsing).Content | ConvertFrom-Json | |
foreach ($item in $r.Answer) | |
{ | |
Write-Host $item | |
} |
This file contains 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
$domain = "quad9.net" | |
$url = "https://dns.quad9.net:5053/dns-query?name=$($domain)" | |
$r= (Invoke-WebRequest -Uri $url -UseBasicParsing).Content | ConvertFrom-Json | |
foreach ($item in $r.Answer) | |
{ | |
Write-Host $item | |
} |
Hey sorry missed the notification for this, yeah for sure. Would be cool if you could give me a credit on it or something but all good if too hard haha.
Hey @matt40k
I have also updated it as well so now you can use -type and it'll resolve those records when using Google or CloudFlare, updated version is below:
Resolve-DnsSSL -Domains <Domains Array> -Type <DNS Record Type> -Provider <CloudFlare, Google, Quad9>
Function Resolve-DnsSSL{
param (
[Parameter(Mandatory=$True)]
[array]$domains,
[Parameter()]
[array]$Type = 'A',
[Parameter()]
[ValidateSet("CloudFlare","Google","Quad9")]
[String]$Provider = "CloudFlare"
)
Foreach ($domain in $domains) {
switch ($Provider) {
"CloudFlare" {$url = 'https://cloudflare-dns.com/dns-query?name='+$domain+'&type='+$type; break}
"Google" {$url = 'https://dns.google.com/resolve?name=' + $domain + '&type='+$type; break}
"Quad9" {$url = 'https://dns.quad9.net:5053/dns-query?name=' + $domain; break}
}
$header = @{"accept"="application/dns-json"}
$response = (Invoke-WebRequest -Uri $url -Headers $header -UseBasicParsing)
if ($response.Content.GetType().name -eq "Byte[]") {
$json = [System.Text.Encoding]::UTF8.GetString($response.Content)
}
Else {
$json = $response.Content
}
$content = $json | ConvertFrom-Json
$content.Answer
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cheers @corey-alford, you ok if I use that and add it to the PSGallery?