In the latest versions of Windows, the client and telnet service are not installed by default. They are available as installable functions. Unfortunately, turning on telnet often requires a restart computer. The connection test can be performed with the ping command, but does not perform any tracing or port testing. In most network problems we need to use ping command with tracert. Also telnet for check for open ports.
PowerShell Test-NetConnection
The Test-NetConnection command is the successor to Test-Connection but provides more information. Let's do a simple test to Google:
PS C:\> Test-NetConnection 8.8.8.8
ComputerName : 8.8.8.8
RemoteAddress : 8.8.8.8
InterfaceAlias : Ethernet 2
SourceAddress : 192.168.1.10
PingSucceeded : True
PingReplyDetails (RTT) : 9 ms
The command returns a lot of information, usually this is enough to find a network problem (if any). It will display the interface, source IP and if the ping was successful.
Detailed Informations
If we need first hop in the lookup (nslookup), we can add the
-InformationLevel "Detailed"
parameter to the command.
PS C:\> Test-NetConnection 8.8.8.8 -InformationLevel Detailed
ComputerName : 8.8.8.8
RemoteAddress : 8.8.8.8
NameResolutionResults : 8.8.8.8
dns.google
InterfaceAlias : Ethernet 2
SourceAddress : 192.168.1.10
NetRoute (NextHop) : 192.168.1.1
PingSucceeded : True
PingReplyDetails (RTT) : 9 ms
Simple test connection (like ping)
Or if we need a simple connection test to the target IP address or website we
can use
-InformationLevel "Quiet"
which will return us a bollean value.
PS C:\> Test-NetConnection google.com -InformationLevel Quiet
True
Test open TCP port
I wrote at the beginning of the post that an open port usually checks with
telnet. The Test-NetConnection command can also check whether a specific port
is open or not. Just add the
-Port
parameter with number of port to the command.
PS C:\> Test-NetConnection google.com -Port 80
ComputerName : google.com
RemoteAddress : 172.217.16.14
RemotePort : 80
InterfaceAlias : Ethernet 2
SourceAddress : 192.168.1.10
TcpTestSucceeded : True
PS C:\> Test-NetConnection google.com -Port 21
WARNING: TCP connect to (172.217.16.14 : 21) failed
ComputerName : google.com
RemoteAddress : 172.217.16.14
RemotePort : 21
InterfaceAlias : Ethernet 2
SourceAddress : 192.168.1.10
PingSucceeded : True
PingReplyDetails (RTT) : 10 ms
TcpTestSucceeded : False
As you can see, port 80 is open but 21 is closed. You can notice an interesting thing - if the port is closed, the command will test if the ping is successful.
Comments
Post a Comment