-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCheck-Domains.ps1
587 lines (574 loc) · 22.6 KB
/
Check-Domains.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
#Requires -Version 7
<#
.SYNOPSIS
Check Domains Health
.DESCRIPTION
Checks a list of domains to see if they are available or not.
.EXAMPLE
.\Check-Domains.ps1 -Mode TCP -Port 80 -Timeout 5 -Concurrency 20
.EXAMPLE
.\Check-Domains.ps1 -Mode DNS -DNSServer 1.1.1.1 -Concurrency 10 -File otherdomains.txt
.EXAMPLE
.\Check-Domains.ps1 -Mode DOH -DOHServer Cloudflare -Concurrency 10
.EXAMPLE
.\Check-Domains.ps1 -Mode DOH -DOHServer Google -Http3 -Concurrency 100
.EXAMPLE
.\Check-Domains.ps1 -Mode ICMP -Timeout 10 -Concurrency 5 -File "D:\domainlist\domains.txt"
.NOTES
This script is published under MIT license.
.LINK
https://github.com/Chocolate4U/Domain-Health-Checker
.PARAMETER Mode
Specifies the working mode of script. Available options: TCP, DNS, DOH, ICMP
.PARAMETER Port
Specifies the port for TCP mode.
.PARAMETER DNSServer
Specifies the DNS Server for DNS mode. Only IPv4 is allowed.
.PARAMETER DOHServer
Specifies the DNS over HTTPS Server for DOH mode. Available options: Cloudflare, Google
.PARAMETER Http3
If set, DOH request will use Http3 otherwise Http2 will be used.
.PARAMETER Timeout
Specifies the timeout for each check. Only available in TCP and ICMP modes.
.PARAMETER Concurrency
Specifies how many Domains to get processed at the same time. Available in all modes.
.PARAMETER File
Specifies the path to the file which contains domain addresses. If not set, the script searches for domains.txt in current directory.
.PARAMETER Quiet
If set, Script will skip connectivity checks and will close after completion.
#>
[CmdletBinding(PositionalBinding = $false)]
param(
[Parameter()]
[ValidateSet('TCP', 'DNS', 'DOH', 'ICMP', ErrorMessage = "Mode '{0}' is invalid, It can only be one of: '{1}'")]
[string]$Mode,
[Parameter()]
[ValidateSet(80, 443, ErrorMessage = "Port '{0}' is invalid, It can only be one of: '{1}'")]
[int]$Port,
[Parameter()]
[ValidatePattern("^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$", ErrorMessage = "DNSServer '{0}' is invalid, It can only be a valid IPv4 Address.")]
[string]$DNSServer,
[Parameter()]
[ValidateSet('Cloudflare', 'Google', ErrorMessage = "DOHServer '{0}' is invalid, It can only be one of: '{1}'")]
[string]$DOHServer,
[Parameter()]
[switch]$Http3,
[Parameter()]
[ValidateRange(1, 3600)]
[int]$Timeout,
[Parameter()]
[ValidateRange(1, 10000)]
[int]$Concurrency,
[Parameter()]
[string]$File,
[Parameter()]
[switch]$Quiet
)
function Get-Mode {
Write-Host ">> This Script will check Domains in a text file for availability." -ForegroundColor Cyan
Write-Host ">> By default it searches for <domains.txt> in the current directory." -ForegroundColor Cyan
Write-Host ">> For each prompt just press <Enter> to use default values." -ForegroundColor Cyan
Write-Host ">> For help and documentation on CLI usage, please run 'Get-Help .\Check-Domains.ps1'" -ForegroundColor Cyan
Write-Host ">> IT can work in the following modes:" -ForegroundColor Cyan
Write-Host ""
Write-Host "1.TCP [Makes a TCP connection to target Website's Webserver and checks for a response]" -ForegroundColor Green
Write-Host "2.DNS [Check if target Website has a valid DNS record]" -ForegroundColor Green
Write-Host "3.DOH [Check if target Website has a valid DNS record using DNS over HTTPS API]" -ForegroundColor Green
Write-Host "4.ICMP [Send Ping requests to target Website's Webserver and checks for a response]" -ForegroundColor Green
Write-Host ""
$ModeInput = Read-Host ">> Please Enter operating Mode name or number: 1[TCP], 2[DNS], 3[DOH], 4[ICMP] [Default: TCP]"
if (([string]$null -eq $ModeInput) -or ("1" -eq $ModeInput) -or ("TCP" -eq $ModeInput)) {
$Mode = "1"
Write-Host ">> Mode: TCP" -ForegroundColor Green
}
elseif ("2" -eq $ModeInput -or ("DNS" -eq $ModeInput)) {
$Mode = "2"
Write-Host ">> Mode: DNS" -ForegroundColor Green
}
elseif ("3" -eq $ModeInput -or ("DOH" -eq $ModeInput)) {
$Mode = "3"
Write-Host ">> Mode: DOH" -ForegroundColor Green
}
elseif ("4" -eq $ModeInput -or ("ICMP" -eq $ModeInput)) {
$Mode = "4"
Write-Host ">> Mode: ICMP" -ForegroundColor Green
}
else {
Write-Host $ModeInput "!! is invalid, Please choose a valid option" -ForegroundColor Red
Get-Mode
}
$Mode
}
function Get-Port {
Write-Host ">> Please select the port to connect to target website: [Default: 80]"
Write-Host "[1] 80" -ForegroundColor Green
Write-Host "[2] 443" -ForegroundColor Green
$PortInput = Read-Host "Please Enter"
if (([string]$null -eq $PortInput) -or ("1" -eq $PortInput) -or ("80" -eq $PortInput)) {
[int]$Port = 80
Write-Host "80[HTTP]" -ForegroundColor Green
}
elseif (("2" -eq $PortInput) -or ("443" -eq $PortInput)) {
[int]$Port = 443
Write-Host "443[HTTPS]" -ForegroundColor Green
}
else {
Write-Host $PortInput "!! is invalid, Please try again" -ForegroundColor Red
Get-Port
}
$Port
}
function Get-Timeout {
$TimeoutInput = Read-Host "Please Enter Timeout for each request in seconds: [Default: 5s]"
if ([string]$null -eq $TimeoutInput) {
[int]$Timeout = 5
}
else {
try {
$Timeout = [int]$TimeoutInput
}
catch {
Write-Host $TimeoutInput "!! is invalid, Please input a number in seconds" -ForegroundColor Red
Get-Timeout
}
}
$Timeout
}
function Get-Concurrency {
$InputConcurrency = Read-Host "How many domains do you want to process in parallel? [Default: 10]"
if ([string]$null -eq $InputConcurrency) {
[int]$Concurrency = 10
}
else {
try {
$Concurrency = [int]$InputConcurrency
}
catch {
Write-Host $InputConcurrency "!! is invalid, Please input a number" -ForegroundColor Red
Concurrency
}
}
$Concurrency
}
function Test-Connectivity {
Write-Host "* Checking Internet connectivity..." -ForegroundColor Cyan
if ((Test-Connection -TargetName 8.8.8.8 -Quiet) -or (Test-Connection -TargetName google.com -TcpPort 80) -or (Test-Connection -TargetName 1.1.1.1 -Quiet) -or (Test-Connection -TargetName cloudflare.com -TcpPort 80)) {
Write-Host "* Good, You have Internet connection" -ForegroundColor Cyan
}
else {
Write-Host "* NO Internet connection detected, Please check your connection and try again" -ForegroundColor Red
Read-Host -Prompt "Press Enter to exit"
exit
}
}
function Get-DNSServer {
Write-Host ">> What DNS Server do you want to use? [Default: System]"
Write-Host "[1] System"
Write-Host "[2] CloudFlare"
Write-Host "[3] Google"
Write-Host "[4] Quad9"
Write-Host "Or Enter Manually (Only IPv4)"
$DNSInput = Read-Host "Please Enter"
if ($IsWindows) {
if (([string]$null -eq $DNSInput) -or (1 -eq $DNSInput) -or ("System" -eq $DNSInput)) {
$DNSServer = $null
Write-Host ">> DNS Server: System" -ForegroundColor Green
}
elseif ((2 -eq $DNSInput) -or ("CloudFlare" -eq $DNSInput)) {
$DNSServer = "-Server 1.1.1.1"
Write-Host ">> DNS Server: CloudFlare [1.1.1.1]" -ForegroundColor Green
}
elseif ((3 -eq $DNSInput) -or ("Google" -eq $DNSInput)) {
$DNSServer = "-Server 8.8.8.8"
Write-Host ">> DNS Server: Google [8.8.8.8]" -ForegroundColor Green
}
elseif ((4 -eq $DNSInput) -or ("Quad9" -eq $DNSInput)) {
$DNSServer = "-Server 9.9.9.9"
Write-Host ">> DNS Server: Quad9 [9.9.9.9]" -ForegroundColor Green
}
elseif ($DNSInput -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") {
$DNSServer = "-Server " + $DNSInput
Write-Host ">> DNS Server:"$DNSInput -ForegroundColor Green
}
else {
Write-Host $DNSInput "!! is invalid, Please try again" -ForegroundColor Red
Get-DNSServer
}
$DNSServer
}
else {
if (([string]$null -eq $DNSInput) -or (1 -eq $DNSInput) -or ("System" -eq $DNSInput)) {
$DNSServer = $null
Write-Host ">> DNS Server: System" -ForegroundColor Green
}
elseif ((2 -eq $DNSInput) -or ("CloudFlare" -eq $DNSInput)) {
$DNSServer = '"' + '@1.1.1.1' + '"'
Write-Host ">> DNS Server: CloudFlare [1.1.1.1]" -ForegroundColor Green
}
elseif ((3 -eq $DNSInput) -or ("Google" -eq $DNSInput)) {
$DNSServer = '"' + '@8.8.8.8' + '"'
Write-Host ">> DNS Server: Google [8.8.8.8]" -ForegroundColor Green
}
elseif ((4 -eq $DNSInput) -or ("Quad9" -eq $DNSInput)) {
$DNSServer = '"' + '@9.9.9.9' + '"'
Write-Host ">> DNS Server: Quad9 [9.9.9.9]" -ForegroundColor Green
}
elseif ($DNSInput -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") {
$DNSServer = '"' + '@' + $DNSInput + '"'
Write-Host ">> DNS Server:"$DNSInput -ForegroundColor Green
}
else {
Write-Host $DNSInput "!! is invalid, Please try again" -ForegroundColor Red
Get-DNSServer
}
$DNSServer
}
}
function Get-DOHServer {
Write-Host ">> What DNS over HTTPS Server do you want to use? [Default: CloudFlare]"
Write-Host "[1] CloudFlare"
Write-Host "[2] Google"
$DNSInput = Read-Host "Please Enter"
if (([string]$null -eq $DNSInput) -or (1 -eq $DNSInput) -or ("CloudFlare" -eq $DNSInput)) {
$DOHServer = 'https://cloudflare-dns.com/dns-query'
$DOHInfo = 'CloudFlare[cloudflare-dns.com]'
Write-Host ">> DOH Server:" $DOHInfo -ForegroundColor Green
}
elseif ((2 -eq $DNSInput) -or ("Google" -eq $DNSInput)) {
$DOHServer = 'https://dns.google/resolve'
$DOHInfo = 'Google[dns.google]'
Write-Host ">> DOH Server:" $DOHInfo -ForegroundColor Green
}
else {
Write-Host $DNSInput "!! is invalid, Please try again" -ForegroundColor Red
Get-DOHServer
}
$DOHServer
$DOHInfo
}
function Test-Domains-TCP {
if (!($Port)) {
$Port = Get-Port
}
if (!($Timeout)) {
$Timeout = Get-Timeout
Write-Host $Timeout -ForegroundColor Green
}
if (!($Concurrency)) {
$Concurrency = Get-Concurrency
Write-Host $Concurrency -ForegroundColor Green
}
Write-Host "* Script started at >>" (Get-Date) -ForegroundColor Cyan
Write-Host "* Selected Mode >> TCP" -ForegroundColor Cyan
Write-Host "* Selected Port >> $Port" -ForegroundColor Cyan
Write-Host "* Timeout >> $Timeout Seconds" -ForegroundColor Cyan
Write-Host "* Concurrency >> $Concurrency" -ForegroundColor Cyan
if (!($Quiet)) {
Test-Connectivity
}
Write-Host "* Initializing TCP Test..., Please keep Internet Connected" -ForegroundColor Cyan
Start-Sleep -Seconds 1
if ($File) {
$domains = Get-Content -Path $File | Sort-Object
}
else {
$domains = Get-Content -Path "domains.txt" | Sort-Object
}
$output = @()
$output += $domains | ForEach-Object -Parallel {
$TestTCP = Test-Connection -IPv4 -TargetName $_ -TcpPort $using:Port -TimeoutSeconds $using:Timeout -ErrorAction Ignore
if ($TestTCP) {
Write-Host $_ ">> TCP Test Succeeded -> on Port $using:Port" -ForegroundColor Green
$result = "OK"
}
else {
Write-Host $_ "!! TCP Test Failed" -ForegroundColor Red
$result = "DEAD"
}
[PSCustomObject]@{
'Domain' = $_
'Result' = $result
}
} -ThrottleLimit $Concurrency
$output | Sort-Object -Property Domain | Export-Csv -Path ".\Results-TCP.csv"
}
function Test-Domains-DNS {
if ($IsWindows) {
if (!($DNSServer)) {
$DNSServer = Get-DNSServer
}
else {
$DNSServer = "-Server " + $DNSServer
}
if (!($Concurrency)) {
$Concurrency = Get-Concurrency
Write-Host $Concurrency -ForegroundColor Green
}
Write-Host "* Script started at >>" (Get-Date) -ForegroundColor Cyan
Write-Host "* Selected Mode >> DNS" -ForegroundColor Cyan
Write-Host "* Selected DNS Server >>" $DNSServer -ForegroundColor Cyan
Write-Host "* Concurrency >>" $Concurrency -ForegroundColor Cyan
if (!($Quiet)) {
Test-Connectivity
}
Write-Host "* Initializing DNS Test..., Please keep Internet Connected" -ForegroundColor Cyan
Clear-DnsClientCache
Start-Sleep -Seconds 1
if ($File) {
$domains = Get-Content -Path $File | Sort-Object
}
else {
$domains = Get-Content -Path "domains.txt" | Sort-Object
}
$output = @()
$output += $domains | ForEach-Object -Parallel {
$ResolveCommand = "Resolve-DnsName -DnsOnly -Name " + $_ + " -NoHostsFile " + $using:DNSServer + " -Type A -ErrorAction SilentlyContinue"
$resolve = Invoke-Expression $ResolveCommand
$ErrorMessage = (get-Error).Exception.Message
if ($resolve) {
[string]$IP = $resolve.IP4Address
Write-Host $_ ">> DNS Query Succeded ->" $IP -ForegroundColor Green
$result = "OK"
}
else {
$IP = "N/A"
Write-Host $_ "!! DNS Query Failed ->" $ErrorMessage -ForegroundColor Red
$result = "DEAD"
}
[PSCustomObject]@{
'Domain' = $_
'Result' = $result
'IP' = $IP
'Error' = $ErrorMessage
}
$Error.Clear()
} -ThrottleLimit $Concurrency
}
else {
if (!($DNSServer)) {
$DNSServer = Get-DNSServer
}
else {
$DNSServer = '"' + "@" + $DNSServer + '"'
}
if (!($Concurrency)) {
$Concurrency = Get-Concurrency
Write-Host $Concurrency -ForegroundColor Green
}
Write-Host "* Script started at >>" (Get-Date) -ForegroundColor Cyan
Write-Host "* Selected Mode >> DNS" -ForegroundColor Cyan
Write-Host "* Selected DNS Server >>" $DNSServer -ForegroundColor Cyan
Write-Host "* Concurrency >>" $Concurrency -ForegroundColor Cyan
if (!($Quiet)) {
Test-Connectivity
}
Write-Host "* Initializing DNS Test..., Please keep Internet Connected" -ForegroundColor Cyan
Start-Sleep -Seconds 1
if ($File) {
$domains = Get-Content -Path $File | Sort-Object
}
else {
$domains = Get-Content -Path "domains.txt" | Sort-Object
}
$output = @()
$output += $domains | ForEach-Object -Parallel {
$ResolveCommand = "dig -t A " + $_ + " +short " + $using:DNSServer
$resolve = Invoke-Expression $ResolveCommand
[string]$IP = $resolve | select-string -raw -Pattern "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$"
if ($IP) {
Write-Host $_ ">> DNS Query Succeded ->" $IP -ForegroundColor Green
$result = "OK"
}
else {
$IP = "N/A"
Write-Host $_ "!! DNS Query Failed" -ForegroundColor Red
$result = "DEAD"
}
[PSCustomObject]@{
'Domain' = $_
'Result' = $result
'IP' = $IP
}
} -ThrottleLimit $Concurrency
}
$output | Sort-Object -Property Domain | Export-Csv -Path ".\Results-DNS.csv"
}
function Test-Domains-DOH {
if (!($DOHServer)) {
$DOH = Get-DOHServer
$URL = $DOH[0]
$DOHInfo = $DOH[1]
}
elseif ("cloudflare" -eq $DOHServer) {
$URL = 'https://cloudflare-dns.com/dns-query'
$DOHInfo = 'CloudFlare[cloudflare-dns.com]'
}
elseif ("Google" -eq $DOHServer) {
$URL = 'https://dns.google/resolve'
$DOHInfo = 'Google[dns.google]'
}
if (!($Concurrency)) {
$Concurrency = Get-Concurrency
Write-Host $Concurrency -ForegroundColor Green
}
if ($Http3) {
$HttpVersion = '3.0'
}
else {
$HttpVersion = '2.0'
}
Write-Host "* Script started at >>" (Get-Date) -ForegroundColor Cyan
Write-Host "* Selected Mode >> DOH" -ForegroundColor Cyan
Write-Host "* Selected DOH Server >>" $DOHInfo -ForegroundColor Cyan
Write-Host "* Concurrency >>" $Concurrency -ForegroundColor Cyan
Write-Host "* Using HTTP$HttpVersion" -ForegroundColor Cyan
if (!($Quiet)) {
Test-Connectivity
}
Write-Host "* Initializing DOH Test..., Please keep Internet Connected" -ForegroundColor Cyan
Start-Sleep -Seconds 1
if ($File) {
$domains = Get-Content -Path $File | Sort-Object
}
else {
$domains = Get-Content -Path "domains.txt" | Sort-Object
}
$header = @{"accept" = "application/dns-json" }
$output = @()
$output += $domains | ForEach-Object -Parallel {
try {
$body = @{
"name" = $_
"type" = "A"
}
$Response = Invoke-RestMethod -Uri $using:URL -Body $body -Headers $using:header -Method Get -HttpVersion $using:HttpVersion -SslProtocol Tls13 -MaximumRetryCount 3 -SkipHeaderValidation -SkipHttpErrorCheck -ErrorAction SilentlyContinue
if (0 -eq ($Response.Status)) {
[string]$IP = ($Response.Answer).data
Write-Host $_ ">> DOH Query Succeded ->" $IP -ForegroundColor Green
$result = "OK"
}
else {
$IP = "N/A"
Write-Host $_ "!! DOH Query Failed with Status Code" ($Response.Status) -ForegroundColor Red
$result = "DEAD"
}
[PSCustomObject]@{
'Domain' = $_
'Result' = $result
'Status Code' = ($Response.Status)
'IP' = $IP
}
}
catch {
Write-Host $_ "!! DOH Connection Failed" -ForegroundColor Yellow
}
} -ThrottleLimit $Concurrency
$output | Sort-Object -Property Domain | Export-Csv -Path ".\Results-DOH.csv"
}
function Test-Domains-ICMP {
if (!($Timeout)) {
$Timeout = Get-Timeout
Write-Host $Timeout -ForegroundColor Green
}
if (!($Concurrency)) {
$Concurrency = Get-Concurrency
Write-Host $Concurrency -ForegroundColor Green
}
Write-Host "* Script started at >>" (Get-Date) -ForegroundColor Cyan
Write-Host "* Selected Mode >> ICMP/Ping" -ForegroundColor Cyan
Write-Host "* Concurrency >>" $Concurrency -ForegroundColor Cyan
if (!($Quiet)) {
Test-Connectivity
}
Write-Host "* Initializing ICMP/Ping Test..., Please keep Internet Connected" -ForegroundColor Cyan
Start-Sleep -Seconds 1
if ($File) {
$domains = Get-Content -Path $File | Sort-Object
}
else {
$domains = Get-Content -Path "domains.txt" | Sort-Object
}
$output = @()
$output += $domains | ForEach-Object -Parallel {
$TestICMP = Test-Connection -IPv4 -TargetName $_ -TimeoutSeconds $using:Timeout -ErrorAction SilentlyContinue
$LatencyResults = $TestICMP | Measure-Object -Property Latency -Minimum -Maximum -Average
if ($TestICMP -and (0 -ne $LatencyResults.Average)) {
Write-Host $_ ">> ICMP Test Succeeded -> Average Latency -> "$LatencyResults.Average -ForegroundColor Green
$result = "OK"
$IP = $TestICMP.DisplayAddress | Out-String -Stream | select-string -raw -Pattern "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$" | Get-Unique
$Ping1 = $TestICMP.Status[0]
$Latency1 = $TestICMP.Latency[0]
$Ping2 = $TestICMP.Status[1]
$Latency2 = $TestICMP.Latency[1]
$Ping3 = $TestICMP.Status[2]
$Latency3 = $TestICMP.Latency[2]
$Ping4 = $TestICMP.Status[3]
$Latency4 = $TestICMP.Latency[3]
$LatencyMin = $LatencyResults.Minimum
$LatencyMax = $LatencyResults.Maximum
$LatencyAvg = $LatencyResults.Average
}
else {
Write-Host $_ "!! ICMP Test Failed" -ForegroundColor Red
$result = "DEAD"
$IP = "N/A"
$Ping1 = "N/A"
$Latency1 = "N/A"
$Ping2 = "N/A"
$Latency2 = "N/A"
$Ping3 = "N/A"
$Latency3 = "N/A"
$Ping4 = "N/A"
$Latency4 = "N/A"
$LatencyMin = "N/A"
$LatencyMax = "N/A"
$LatencyAvg = "N/A"
}
[PSCustomObject]@{
'Domain' = $_
'Result' = $result
'IP' = $IP
'Ping Status[1]' = $Ping1
'Latency[1]' = $Latency1
'Ping Status[2]' = $Ping2
'Latency[2]' = $Latency2
'Ping Status[3]' = $Ping3
'Latency[3]' = $Latency3
'Ping Status[4]' = $Ping4
'Latency[4]' = $Latency4
'Latency[Minimum]' = $LatencyMin
'Latency[Maximum]' = $LatencyMax
'Latency[Average]' = $LatencyAvg
}
} -ThrottleLimit $Concurrency
$output | Sort-Object -Property Domain | Export-Csv -Path ".\Results-ICMP.csv"
}
function Invoke-Main {
if (!($Mode)) {
$Mode = Get-Mode
}
$duration = [System.Diagnostics.Stopwatch]::StartNew()
if (("1" -eq $Mode) -or ("TCP" -eq $Mode)) {
Test-Domains-TCP
}
elseif (("2" -eq $Mode) -or ("DNS" -eq $Mode)) {
Test-Domains-DNS
}
elseif (("3" -eq $Mode) -or ("DOH" -eq $Mode)) {
Test-Domains-DOH
}
elseif (("4" -eq $Mode) -or ("ICMP" -eq $Mode)) {
Test-Domains-ICMP
}
$duration.stop()
Write-Host "Script finished in" $duration.Elapsed.Hours "Hours" $duration.Elapsed.Minutes "Minutes" $duration.Elapsed.Seconds "Seconds" -ForegroundColor Green
if (!($Quiet)) {
Read-Host -Prompt "Press Enter to exit..."
}
}
Write-Host "█▀▄ █▀█ █▀▄▀█ ▄▀█ █ █▄░█ █░█ █▀▀ ▄▀█ █░░ ▀█▀ █░█ █▀▀ █░█ █▀▀ █▀▀ █▄▀ █▀▀ █▀█ " -ForegroundColor DarkCyan
Write-Host "█▄▀ █▄█ █░▀░█ █▀█ █ █░▀█ █▀█ ██▄ █▀█ █▄▄ ░█░ █▀█ █▄▄ █▀█ ██▄ █▄▄ █░█ ██▄ █▀▄ " -ForegroundColor DarkCyan -NoNewline
Write-Host " v0.3.1" -ForegroundColor DarkCyan
Write-Host ""
Write-Host ""
Invoke-Main