The more I use PowerShell, the more I like it! I saw a Tweet put out by Scott Bollinger (@kfalconspb) about using a PowerShell cmdlet (here) to see if a port is open on a remote system. After reading the quick blog, my first thought was, “No more telnet”. The PowerShell cmdlet Test-NetConnection followed with a parameter of -port number will test the remote system. Take a look:
Test-NetConnection -ComputerName aws.amazon.com -port 80 ComputerName : aws.amazon.com RemoteAddress : 22.214.171.124 RemotePort : 80 InterfaceAlias : Ethernet SourceAddress : <internal IP> TcpTestSucceeded : True
This looks like good information. I can see port 80 is open because it came back True. What if I want to know the round trip time (RTT) to AWS? Look no further, Test-NetConnection has you covered.
Test-NetConnection -ComputerName aws.amazon.com -InformationLevel Detailed ComputerName : aws.amazon.com RemoteAddress : 126.96.36.199 NameResolutionResults : 188.8.131.52 InterfaceAlias : Ethernet SourceAddress : <internal IP> NetRoute (NextHop) : <internal router> PingSucceeded : True PingReplyDetails (RTT) : 34 ms
Cool! I can see my RTT was 34 ms to get to AWS. This cmdlet arms me with some very powerful information besides pinging the remote host. I can now go back to the system owner with more information than just “yes, it pings”.
I can see putting this in a loop and testing a port on multiple systems or testing a single system and a range of ports to see what’s open and taking action on the results.