external help file | Module Name | online version | schema |
---|---|---|---|
PSNetScanners.dll-Help.xml |
PSNetScanners |
2.0.0 |
Parallel TCP scanner.
Test-TcpAsync
[-Target] <String[]>
[-Port] <Int32[]>
[-ThrottleLimit <Int32>]
[-ConnectionTimeout <Int32>]
[<CommonParameters>]
Test-TcpAsync
is a PowerShell cmdlet that tests TCP connectivity in parallel using TcpClient.ConnectAsync
Method. In essence, it's like Test-NetConnection
with -Port
but faster.
PS ..\> Test-TcpAsync google.com 20, 25, 80, 443
Source Destination Client Port Status
------ ----------- ------ ---- ------
DESKTOP-1111111 google.com 142.251.134.14 80 Opened
DESKTOP-1111111 google.com 142.251.134.14 443 Opened
DESKTOP-1111111 google.com 20 TimedOut
DESKTOP-1111111 google.com 25 TimedOut
PS ..\> Test-TcpAsync google.com, github.com 20, 25, 80, 443
Source Destination Client Port Status
------ ----------- ------ ---- ------
DESKTOP-1111111 google.com 142.251.134.14 443 Opened
DESKTOP-1111111 google.com 142.251.134.14 80 Opened
DESKTOP-1111111 github.com 20.201.28.151 80 Opened
DESKTOP-1111111 github.com 20.201.28.151 443 Opened
DESKTOP-1111111 google.com 20 TimedOut
DESKTOP-1111111 google.com 25 TimedOut
DESKTOP-1111111 github.com 20 TimedOut
DESKTOP-1111111 github.com 25 TimedOut
PS ..\> $result = Test-TcpAsync github.com 20, 80 -ConnectionTimeout 30000
PS ..\> $result
Source Destination Client Port Status
------ ----------- ------ ---- ------
DESKTOP-1111111 github.com 20.201.28.151 80 Opened
DESKTOP-1111111 github.com 20 Closed
PS ..\> $result.Details
Message : A connection attempt failed because the connected party did not properly respond after a period of
time, or established connection failed because connected host has failed to respond.
SocketErrorCode : TimedOut
ErrorCode : 10060
NativeErrorCode : 10060
TargetSite : Void ThrowException(System.Net.Sockets.SocketError, System.Threading.CancellationToken)
Data : {}
InnerException :
HelpLink :
Source : System.Net.Sockets
HResult : -2147467259
StackTrace : at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error,
CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTa
skSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at System.Net.Sockets.TcpClient.CompleteConnectAsync(Task task)
at PSNetScanners.TcpResult.CreateAsync(TcpInput input, Cancellation cancellation, Int32 timeout)
in D:\PSNetScanners\src\PSNetScanners\TcpResult.cs:line 64
PS ..\> Import-Csv targets.csv | Test-TcpAsync
Source Destination Client Port Status
------ ----------- ------ ---- ------
DESKTOP-1111111 google.com 142.251.133.206 80 Opened
DESKTOP-1111111 google.com 142.251.133.206 443 Opened
DESKTOP-1111111 github.com 20.201.28.151 443 Opened
DESKTOP-1111111 github.com 20.201.28.151 80 Opened
DESKTOP-1111111 amazon.com 52.94.236.248 443 Opened
DESKTOP-1111111 cisco.com 72.163.4.185 443 Opened
DESKTOP-1111111 cisco.com 72.163.4.185 80 Opened
DESKTOP-1111111 amazon.com 52.94.236.248 80 Opened
Tip
Both parameters -Target
and -Port
take value from pipeline by property name, if your CSV headers match the parameters names or their aliases, you can use a CSV as input for this cmdlet.
Specifies one or more remote computers, Uris or Ip addresses to test connectivity.
Type: String[]
Parameter Sets: (All)
Aliases: ComputerName, HostName, Host, Server, Address
Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
Specifies one or many TCP ports to test connectivity to the specified targets.
Type: Int32[]
Parameter Sets: (All)
Aliases: p
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Specifies a timeout in milliseconds for each async task.
Note
- If a task is not completed after this timeout, the status will be
TimedOut
. - If your
-ConnectionTimeout
is greater than the maximum timeout ofTcpClient
and the connection fails, the status will beClosed
. - In both cases of a connectivity failure, the
.Details
property will be populated with aSocketException
. - The default value for this parameter is
4000
(4 seconds).
Type: Int32
Parameter Sets: (All)
Aliases: timeout, to, ct
Required: False
Position: Named
Default value: 4000
Accept pipeline input: False
Accept wildcard characters: False
Specifies the maximum number of async tasks to run in parallel.
Note
The default value for -ThrottleLimit
is 50
.
Type: Int32
Parameter Sets: (All)
Aliases: tl
Required: False
Position: Named
Default value: 50
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters. For more information, see about_CommonParameters.