@@ -1179,7 +1179,7 @@ function Read-MXRecord {
11791179
11801180 catch { Write-Verbose $_.Exception.Message }
11811181 }
1182- $ValidationPasses.Add (' Mail exchanger record(s) are present for this domain.' ) | Out-Null
1182+ $ValidationPasses.Add (' Mail exchanger records record(s) are present for this domain.' ) | Out-Null
11831183 $MXRecords = $MXRecords | Sort-Object - Property Priority
11841184
11851185 # Attempt to identify mail provider based on MX record
@@ -2073,9 +2073,11 @@ function Read-WhoisRecord {
20732073 $WhoisRegex = ' ^(?!(?:%|>>>|-+|#|[*]))[^\S\n]*(?<PropName>.+?):(?:[\r\n]+)?(:?(?!([0-9]|[/]{2}))[^\S\r\n]*(?<PropValue>.+))?$'
20742074
20752075 Write-Verbose " Querying WHOIS Server: $Server "
2076- # TCP Client for Whois
2077- $Client = New-Object System.Net.Sockets.TcpClient($Server , 43 )
2076+
20782077 try {
2078+ # TCP Client for Whois
2079+ $Client = New-Object System.Net.Sockets.TcpClient($Server , 43 )
2080+
20792081 # Open TCP connection and send query
20802082 $Stream = $Client.GetStream ()
20812083 $ReferralServers = [System.Collections.Generic.List [string ]]::new()
@@ -2159,16 +2161,18 @@ function Read-WhoisRecord {
21592161 $Results = $LastResult
21602162 }
21612163 }
2162- }
2163-
2164- else {
2164+ } else {
21652165 if ($Results._Raw -Match ' (No match|Not Found|No Data)' ) {
21662166 $first , $newquery = ($Query -split ' \.' )
21672167 if (($newquery | Measure-Object ).Count -gt 1 ) {
21682168 $Query = $newquery -join ' .'
2169- $Results = Read-WhoisRecord - Query $Query - Server $Server - Port $Port
2170- foreach ($s in $Results._ReferralServers ) {
2171- $ReferralServers.Add ($s ) | Out-Null
2169+ try {
2170+ $Results = Read-WhoisRecord - Query $Query - Server $Server - Port $Port
2171+ foreach ($s in $Results._ReferralServers ) {
2172+ $ReferralServers.Add ($s ) | Out-Null
2173+ }
2174+ } catch {
2175+ $Results = $LastResult
21722176 }
21732177 }
21742178 }
@@ -2185,17 +2189,17 @@ function Read-WhoisRecord {
21852189 $Stream.Dispose ()
21862190 }
21872191 }
2188-
2189- # Collect referral server list
2190- $Results._ReferralServers = $ReferralServers
2191-
2192+ if ( $ReferralServers ) {
2193+ # Collect referral server list
2194+ $Results._ReferralServers = $ReferralServers
2195+ }
21922196 # Convert to json and back to preserve object order
21932197 $WhoisResults = $Results | ConvertTo-Json | ConvertFrom-Json
21942198
21952199 # Return Whois results as PSObject
21962200 $WhoisResults
21972201}
2198- # EndRegion './Public/Records/Read-WhoisRecord.ps1' 175
2202+ # EndRegion './Public/Records/Read-WhoisRecord.ps1' 179
21992203# Region './Public/Resolver/Resolve-DnsHttpsQuery.ps1' -1
22002204
22012205function Resolve-DnsHttpsQuery {
@@ -2221,7 +2225,7 @@ function Resolve-DnsHttpsQuery {
22212225
22222226 #>
22232227 [cmdletbinding ()]
2224- Param (
2228+ param (
22252229 [Parameter (Mandatory = $true )]
22262230 [string ]$Domain ,
22272231
@@ -2251,23 +2255,23 @@ function Resolve-DnsHttpsQuery {
22512255 $Uri = $QueryTemplate -f $BaseUri , $Domain , $RecordType
22522256
22532257 $x = 0
2258+ $Exception = $null
22542259 do {
22552260 $x ++
22562261 try {
22572262 $Results = Invoke-RestMethod - Uri $Uri - Headers $Headers - ErrorAction Stop
2258- }
2259-
2260- catch {
2263+ } catch {
2264+ $Exception = $_
22612265 Start-Sleep - Milliseconds 300
22622266 }
22632267 }
22642268 while (-not $Results -and $x -le 3 )
2265- if (! $Results ) { throw $_ }
2269+ if (! $Results ) { throw ' Exception querying resolver {0}: {1} ' -f $Resolver .Resolver , $Exception .Exception.Message }
22662270
22672271 if ($RecordType -eq ' txt' -and $Results.Answer ) {
22682272 if ($Resolver -eq ' Cloudflare' -or $Resolver -eq ' Quad9' ) {
22692273 $Results.Answer | ForEach-Object {
2270- $_.data = $_.data -replace ' "' -replace ' \s+ ' , ' '
2274+ $_.data = $_.data -replace ' " " ' -replace ' " ' , ' '
22712275 }
22722276 }
22732277 $Results.Answer = $Results.Answer | Where-Object { $_.type -eq 16 }
0 commit comments