-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoke-ADPortScan.psm1
57 lines (30 loc) · 2.14 KB
/
Invoke-ADPortScan.psm1
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
Function Invoke-ADPortScan {
Import-Module NetTCPIP
$hostname=read-host "Enter Hostname"
$Ports =
('139','User and Computer Authentication, Replication','DFSN, NetBIOS Session Service, NetLogon'),
('137', 'User and Computer Authentication','NetLogon, NetBIOS Name Resolution'),
('67','DHCP','DHCP' ),
('2535','DHCP','DHCP'),
('9389','AD DS Web Services','SOAP'),
('138','DFS, Group Policy','DFSN, NetLogon, NetBIOS Datagram Service'),
('464','Replication, User and Computer Authentication, Trusts','Kerberos change/set password'),
('123', 'Windows Time, Trusts', 'Windows Time'),
('5722', 'File Replication', 'RPC, DFSR (SYSVOL'),
('135', 'Replication', 'RPC, EPM'),
('25', 'Replication', 'SMTP'),
('445', 'Replication, User and Computer Authentication, Group Policy, Trusts', 'SMB,CIFS,SMB2, DFSN, LSARPC, NbtSS, NetLogonR, SamR, SrvSvc'),
('53', 'User and Computer Authentication, Name Resolution, Trusts', 'DNS'),
('88', 'User and Computer Authentication, Forest Level Trusts', 'Kerberos'),
('3268', 'Directory, Replication, User and Computer Authentication, Group Policy, Trusts', 'LDAP GC'),
('3269', 'Directory, Replication, User and Computer Authentication, Group Policy, Trusts', 'LDAP GC SSL'),
('389', 'Directory, Replication, User and Computer Authentication, Group Policy, Trusts', 'LDAP'),
('636', 'Directory, Replication, User and Computer Authentication, Group Policy, Trusts', 'LDAP SSL') | ForEach-Object {[pscustomobject]@{Port = $_[0]; "PortUsage" = $_[1]; TrafficType = $_[2]}}
$ports | foreach {$port = $_.port;$portusage=$_.PortUsage;$traffictype=$_.TrafficType;Test-NetConnection -computer $hostname -Port $port | select @{name="Hostname";expression={$hostname}},@{name="Port";expression={$port}},@{name="Port Usage";expression={$PortUsage}} ,@{name="Traffic Type";expression={$traffictype}},@{name="Port Is Open";expression={$_.TcpTestSucceeded} } | Export-Csv "c:\temp\ADPorts.csv" -Append -Force -NoTypeInformation }
}
$Net = $null
$_ = $null
$Range = 1024..65535 | foreach {$net + $_ }
$Results = $Range | foreach {
Test-NetConnection -ComputerName localhost -Port $_ }