Skip to content

Commit

Permalink
Catch exceptions with whois recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Mar 16, 2023
1 parent 1902ee5 commit d8dcafa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 10 additions & 9 deletions DNSHealth/Public/Records/Read-WhoisRecord.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ function Read-WhoisRecord {
if ($HasReferral) {
if ($Server -ne $ReferralServer) {
$LastResult = $Results
$Results = Read-WhoisRecord -Query $Query -Server $ReferralServer -Port $Port
if ($Results._Raw -Match '(No match|Not Found|No Data|The queried object does not exist)' -and $TopLevelReferrers -notcontains $Server) {
$Results = $LastResult
}

else {
foreach ($s in $Results._ReferralServers) {
$ReferralServers.Add($s) | Out-Null
try {
$Results = Read-WhoisRecord -Query $Query -Server $ReferralServer -Port $Port
if ($Results._Raw -Match '(No match|Not Found|No Data|The queried object does not exist)' -and $TopLevelReferrers -notcontains $Server) {
$Results = $LastResult
} else {
foreach ($s in $Results._ReferralServers) {
$ReferralServers.Add($s) | Out-Null
}
}
} catch {
$Results = $LastResult
}

}
}

Expand Down
8 changes: 6 additions & 2 deletions Tests/Test-Resolver.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Param(
$Count = 1000
)

$DomainList = (Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/opendns/public-domain-lists/master/opendns-top-domains.txt') -split "`n"
$RandomDomains = $DomainList | Where-Object { $_ } | Get-Random -Count 1000
$RandomDomains = $DomainList | Where-Object { $_ } | Get-Random -Count $Count


$Jobs = $RandomDomains | ForEach-Object -Parallel {
Expand All @@ -9,7 +13,7 @@ $Jobs = $RandomDomains | ForEach-Object -Parallel {
$Start = Get-Date
try {
Set-DnsResolver -Resolver $Resolver
$Result = Resolve-DnsHttpsQuery -Domain $_
$Result = Resolve-DnsHttpsQuery -Domain $_
$Success = $true
}

Expand Down

0 comments on commit d8dcafa

Please sign in to comment.