A Quick Tip To Check If A Port Is Listening On Multiple Computers

by [Published on 9 Feb. 2011 / Last Updated on 9 Jan. 2010]

This article explains how you can check if a port is listening on multiple computers.

On local computer you can always run NetStat -an command to get the list of all the ports listening on the computer. There is no support available natively on Windows Computers or there is no command line tool available to check if a specific port is listening on multiple computers or not. Let's assume we want to check if 3389 port is listening or not on the servers mentioned in the Servers.txt file. To accomplish this, you need to use the script mentioned below:


  • 1. Create a text file: Servers.txt
  • 2. Put all the Server Names in it.
  • 3. Next, copy the following lines in a file and save it save it as CheckPort.CMD
  • REM ***START HERE***
  • Echo Off
  • SetLocal EnableDelayedExpansion
  • IF EXIST Result.csv DEL Result.csv
  • FOR /F "Tokens=*" %%L IN (Servers.txt) DO (
  •    SET ServerName=
  •    SET ServerName=%%L
  •    Psexec.exe \\!ServerName! NetStat -an > Result.txt
  •    Find /i "3389" < Result.txt
  •    IF !ErrorLevel! == 0 (
  •        Echo !ServerName!, Listening >> Result.CSV
  •    ) ELSE (
  •        Echo !ServerName!, Not Listening >> Result.csv
  •    )
  • )
  • REM ***END HERE***

The end result will be stored in a file called Result.csv.

See Also

The Author — Nirmal Sharma

Nirmal Sharma avatar

Nirmal Sharma is a MCSEx3, MCITP, and was awarded Microsoft MVP in Directory Services. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles for various online communities. Nirmal can also be found contributing to PowerShell based Dynamic Packs for ADHealthProf.ITDynamicPacks.Net solutions.

Featured Links