-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutbound.ps1
34 lines (30 loc) · 1.05 KB
/
outbound.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
Param(
#[string[]]$portrange
[Parameter(Mandatory=$True,HelpMessage='Please enter port range (1..n) or list (22,53,80,443)',ParameterSetName='ports')]
[ValidateNotNullOrEmpty()]
[int[]] $ports
)
#Define external host with open ports to test against
[string] $testhost = "allports.exposed"
if (Test-Connection -Count 1 $testhost -Quiet) {
Write-Host "DNS Resolution is working`n" -ForegroundColor Green
}
else {
Write-Host "DNS Translation failed`n" -ForegroundColor Red
}
#Open connection for each port from the range
Foreach ($p in $ports)
{
$Socket = New-Object Net.Sockets.TcpClient
$ErrorActionPreference = 'SilentlyContinue'
#Connect on the given port
$Socket.Connect($testhost, $p)
#Determine if the connection is established
if ($Socket.Connected) {
Write-Host "Outbound port $p is open." -ForegroundColor Green
$Socket.Close()
}
else {
Write-Host "Outbound port $p is closed or filtered." -ForegroundColor Red
}
} #end foreach