Love to code, although it bugs me.

Test open network ports using Powershell

No comments
Most frequently when deploying new scenarios, the task of network connectivity validation has to be performed.
Commonly this is performed using a command line and issuing a “telnet” connection to the desired host on a given port. This is nice when you have a single machine with a couple of connections to be tested.
When the scenario involves tens of machines with different network connection requisites between each other, the telnet procedure is a very slow process, being the typical test cycle:
  1. Open command prompt.
  2. Issue telnet to a given host and port.
  3. On success, close window and return to step 1.
  4. On failure, wait for timeout.
  5. Authorize the network port that failed
  6. Repeat step 2.
  7. On success go to step 1.
This isn’t a time effective test cycle. The ideal test cycle would be:
  1. Open command prompt.
  2. Issue command or script to test all destination hosts on desired ports.
  3. Check status and authorize failed network traffic.
  4. Repeat step 2 and check for success.
The two most annoying things about telnet are that you need to close and open a new window on success and you have to wait for timeout on failure.
To surpass these annoyances, one can use this Powershell function “Test-Port”, available from the Microsoft Technet Script Center Repository.
The syntax of the base usage is really simple. To test conecctivity to this site:
Test-port -computer blog.ozzie.eu -port 80

To address the fact of the ever growing shared network resources to be tested, an Excel spreadsheet can be used to generate the test battery script. Here’s an example you can view and download:





Afterwards, you just copy/paste the powershell column to a .ps1 file. I’ve also included a regular command prompt test column.


HTH.

No comments :

Post a Comment