-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest-TSXPorts.ps1
More file actions
50 lines (41 loc) · 1.36 KB
/
Test-TSXPorts.ps1
File metadata and controls
50 lines (41 loc) · 1.36 KB
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
Param(
$Computername
)
Function Test-TSXOpenTCPPort {
<#
# Proudly borrwed stuff from https://github.com/InfosecMatter/Minimalistic-offensive-security-tools/blob/master/port-scan-tcp.ps1, thank you
#>
param(
$Computername,
$Ports
)
if (!$ports) {
return
}
$result = foreach($p in [array]$ports) {
$Object = New-Object PSCustomObject
$Object | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $ComputerName
$Object | Add-Member -MemberType NoteProperty -Name "Protocol" -Value "TCP"
$Object | Add-Member -MemberType NoteProperty -Name "Port" -Value $p
$t = New-Object system.Net.Sockets.TcpClient
$c = $t.ConnectAsync($ComputerName,$p)
for($i=0; $i -lt 10; $i++) {
if ($c.isCompleted) {
break;
}
Start-Sleep -Milliseconds 100
}
$t.Close();
$r = "Filtered"
if ($c.isFaulted -and $c.Exception -match "actively refused") {
$r = "Closed"
} elseif ($c.Status -eq "RanToCompletion") {
$r = "Open"
}
$Object | Add-Member -MemberType NoteProperty -Name "Status" -Value $r
$Object
}
Return $result
}
Test-TSXOpenTCPPort -Computername $Computername -Ports 80,443,445,3389,5985 | Format-Table -AutoSize
Pause