Checking for running port on Windows cmd

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Using Windows command line is sometimes challenging. Especially if you want to check if a special port is up and running (listening). This post demonstrates how.

Usually in Linux, you would go for

netstat -na | grep ":3128"

But Windows has nothing grep like :-x . Since Windows XP, findstr was introduced. It offers similar functionality to grep.

netstat -ano | findstr ":3128"

Some excerpt from the help

C:\Users>netstat \help
 -a            Displays all connections and listening ports.
 -n            Displays addresses and port numbers in numerical form.
 -o            Displays the owning process ID associated with each connection.

Some example output:

C:\Users>netstat -ano | findstr 3128
  TCP              LISTENING       6348

The last column contains the process id (PID). The pid can be used with a filter in tasklist to retrieve the process name.

C:\Users>tasklist /?
TASKLIST [/S system [/U username [/P [password]]]]
         [/M [module] | /SVC | /V] [/FI filter] [/FO format] [/NH]
    This tool displays a list of currently running processes on
    either a local or remote machine.
Parameter List:
   /FI    filter           Displays a set of tasks that match a
                           given criteria specified by the filter.
    Filter Name     Valid Operators           Valid Value(s)
    -----------     ---------------           --------------------------
    PID             eq, ne, gt, lt, ge, le    PID value
C:\Users>tasklist /FI "PID eq 6348"
Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
cntlm.exe                     6348 Console                    1      5'732 K

If you have cygwin running on the Windows machine, you can stay with grep.

$ netstat -na | grep :3128
  TCP              LISTENING
Please remember the terms for blog comments.