Skip to content

Commit 4120adf

Browse files
committed
Add DNS test script
1 parent f91c64c commit 4120adf

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

route53/dnstest.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
param (
2+
[Parameter(Mandatory)] [string]$hostname,
3+
[Parameter(Mandatory)] [string]$nameserver,
4+
[Parameter(Mandatory)] [int]$iterations,
5+
[Parameter(Mandatory)] [int]$sleeptime
6+
)
7+
8+
function Run-NSLookup {
9+
param (
10+
[Parameter(Mandatory)] [string]$hostname,
11+
[Parameter(Mandatory)] [string]$nameserver
12+
)
13+
14+
$ns = (nslookup.exe $hostname $nameserver)[-2] 2>$null
15+
$lookup = [PSCustomObject]@{
16+
Address = ($ns -split ':')[1].Trim()
17+
}
18+
return $lookup.Address
19+
}
20+
21+
function Iterate-NSLookup {
22+
param (
23+
[Parameter(Mandatory)] [string]$hostname,
24+
[Parameter(Mandatory)] [string]$nameserver,
25+
[Parameter(Mandatory)] [int]$iterations,
26+
[Parameter(Mandatory)] [int]$sleeptime
27+
)
28+
29+
$responses = @{}
30+
write-host "Working..."
31+
32+
for ($i=0; $i -lt $iterations; $i++) {
33+
#Query DNS
34+
try {$ip = Run-NSLookup -hostname $hostname -nameserver $nameserver }
35+
catch { "Name resolution failed. Please check the hostname."; exit}
36+
37+
#if address is in hashtable, increment counter
38+
if ($responses[$ip] -ge 1) { $responses[$ip]++ }
39+
else {
40+
$responses.Add($ip,1)
41+
Write-Host Resolved unique IP: $ip
42+
}
43+
Start-Sleep -seconds $sleeptime
44+
}
45+
46+
$recordlist = @()
47+
$responses.keys | ForEach-Object {
48+
$recordlist += New-Object PSObject -Property @{
49+
'IP'=$_;
50+
'Count'=$responses[$_];
51+
'Percent'="{0:p}" -f ($responses[$_]/$iterations)
52+
}
53+
}
54+
return $recordlist
55+
}
56+
57+
$records = Iterate-NSLookup -hostname $hostname -nameserver $nameserver -iterations $iterations -sleeptime $sleeptime
58+
$records | Format-Table -Property ip,count,percent
59+
Write-Host $records.count "unique responses" for $hostname

0 commit comments

Comments
 (0)