-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectivity.Tests.ps1
35 lines (28 loc) · 1.03 KB
/
Connectivity.Tests.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
param($TargetsFile = "targets.json")
BeforeDiscovery {
$Targets = Get-Content $TargetsFile | ConvertFrom-Json
}
if ($Targets.Ping.Count -gt 0) {
Describe "Ping" {
It "Pings IP <_>" -ForEach $Targets.Ping {
(Get-CimInstance -ClassName Win32_PingStatus -Filter "(Address='$_') and timeout=1000").StatusCode | Should -Be 0
}
}
}
if ($Targets.TCP.Count -gt 0) {
Describe "TCP" {
$Bindings = $Targets.TCP | % {$Dest = $_.Target; $_.Port | % {"$($Dest):$_"}}
It "Tests TCP for <_>" -ForEach $Bindings {
$IP, $Port = $_.Split(":")
$Result = (New-Object System.Net.Sockets.TcpClient).ConnectAsync($IP, $Port).Wait(150)
$Result | Should -Be $true
}
}
}
if ($Targets.DNS.Targets.Count -gt 0) {
Describe "DNS" {
It "Resolves DNS for <_.Target>" -ForEach $Targets.DNS.Targets {
(Resolve-DnsName -Type A -Name $_.Target -DnsOnly -Server $Targets.DNS.Server).IPAddress | Should -Be $_.ShouldResolveTo
}
}
}