-
Notifications
You must be signed in to change notification settings - Fork 2
/
Get-ListeningTCPConnections.ps1
39 lines (29 loc) · 1.26 KB
/
Get-ListeningTCPConnections.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
<#
.SYNOPSIS
Display a List of Ports a device is listening on.
.DESCRIPTION
Display a List of Ports a device is listening on.
.EXAMPLE
Get-ListeningTCPConnections
.NOTES
Daryl Bizsley 2015
#>
Function Get-ListeningTCPConnections {
[cmdletbinding()]
param(
)
try {
$TCPProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
$Connections = $TCPProperties.GetActiveTcpListeners()
foreach($Connection in $Connections) {
if($Connection.address.AddressFamily -eq "InterNetwork" ) { $IPType = "IPv4" } else { $IPType = "IPv6" }
$OutputObj = New-Object -TypeName PSobject
$OutputObj | Add-Member -MemberType NoteProperty -Name "LocalAddress" -Value $connection.Address
$OutputObj | Add-Member -MemberType NoteProperty -Name "ListeningPort" -Value $Connection.Port
$OutputObj | Add-Member -MemberType NoteProperty -Name "IPV4Or6" -Value $IPType
$OutputObj
}
} catch {
Write-Error "Failed to get listening connections. $_"
}
}