[windows] Command line for looking at specific port

Is there a way to examine the status of a specific port from the Windows command line? I know I can use netstat to examine all ports but netstat is slow and looking at a specific port probably isn't.

This question is related to windows networking port command-prompt

The answer is


For port 80, the command would be : netstat -an | find "80" For port n, the command would be : netstat -an | find "n"

Here, netstat is the instruction to your machine

-a : Displays all connections and listening ports -n : Displays all address and instructions in numerical format (This is required because output from -a can contain machine names)

Then, a find command to "Pattern Match" the output of previous command.


In RHEL 7, I use this command to filter several ports in LISTEN State:

sudo netstat -tulpn | grep LISTEN | egrep '(8080 |8082 |8083 | etc )'

Use the lsof command "lsof -i tcp:port #", here is an example.

$ lsof -i tcp:1555 
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    27330 john  121u  IPv4 36028819      0t0  TCP 10.10.10.1:58615->10.10.10.10:livelan (ESTABLISHED)
java    27330 john  201u  IPv4 36018833      0t0  TCP 10.10.10.1:58586->10.10.10.10:livelan (ESTABLISHED)
java    27330 john  264u  IPv4 36020018      0t0  TCP 10.10.10.1:58598->10.10.10.10:livelan (ESTABLISHED)
java    27330 john  312u  IPv4 36058194      0t0  TCP 10.10.10.1:58826->10.10.10.10:livelan (ESTABLISHED)

This will help you

netstat -atn | grep <port no>          # For tcp
netstat -aun | grep <port no>           # For udp
netstat -atun | grep <port no>          # For both

It will give you all active sockets on a specific IP:

netstat -an | find "172.20.1.166"

when I have problem with WAMP apache , I use this code for find which program is using port 80.

netstat -o -n -a | findstr 0.0:80

enter image description here

3068 is PID, so I can find it from task manager and stop that process.


I use:

netstat –aon | find "<port number>"

here o represents process ID. now you can do whatever with the process ID. To terminate the process, for e.g., use:

taskkill /F /pid <process ID>

Here is the easy solution of port finding...

In cmd:

netstat -na | find "8080"

In bash:

netstat -na | grep "8080"

In PowerShell:

netstat -na | Select-String "8080"

netstat -a -n | find /c "10.240.199.9:8080"

it will give you number of sockets active on a specific IP and port(Server port number)


You can use the netstat combined with the -np flags and a pipe to the find or findstr commands.

Basic Usage is as such:

netstat -np <protocol> | find "port #"

So for example to check port 80 on TCP, you can do this: netstat -np TCP | find "80" Which ends up giving the following kind of output:

TCP    192.168.0.105:50466    64.34.119.101:80       ESTABLISHED
TCP    192.168.0.105:50496    64.34.119.101:80       ESTABLISHED

As you can see, this only shows the connections on port 80 for the TCP protocol.


As noted elsewhere: use netstat, with appropriate switches, and then filter the results with find[str]

Most basic:

netstat -an | find ":N"

or

netstat -a -n | find ":N"

To find a foreign port you could use:

netstat -an | findstr ":N[^:]*$"

To find a local port you might use:

netstat -an | findstr ":N.*:[^:]*$"

Where N is the port number you are interested in.

-n ensures all ports will be numerical, i.e. not returned as translated to service names.

-a will ensure you search all connections (TCP, UDP, listening...)

In the find string you must include the colon, as the port qualifier, otherwise the number may match either local or foreign addresses.

You can further narrow narrow the search using other netstat switches as necessary...

Further reading (^0^)

netstat /?

find /?

findstr /?

This command will show all the ports and their destination address:

netstat -f 

To improve upon @EndUzr's response:

To find a foreign port (IPv4 or IPv6) you can use:

netstat -an | findstr /r /c:":N [^:]*$"

To find a local port (IPv4 or IPv6) you can use:

netstat -an | findstr /r /c:":N *[^ ]*:[^ ]* "

Where N is the port number you are interested in. The "/r" switch tells it to process it as regexp. The "/c" switch allows findstr to include spaces within search strings instead of treating a space as a search string delimiter. This added space prevents longer ports being mistreated - for example, ":80" vs ":8080" and other port munging issues.

To list remote connections to the local RDP server, for example:

netstat -an | findstr /r /c:":3389 *[^ ]*:[^ ]*"

Or to see who is touching your DNS:

netstat -an | findstr /r /c:":53 *[^ ]*:[^ ]*"

If you want to exclude local-only ports you can use a series of exceptions with "/v" and escape characters with a backslash:

netstat -an | findstr /v "0.0.0.0 127.0.0.1 \[::\] \[::1\] \*\:\*" | findstr /r /c:":80 *[^ ]*:[^ ]*"

For Windows 8 User : Open Command Prompt, type netstat -an | find "your port number" , enter .

If reply comes like LISTENING then the port is in use, else it is free .


Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to networking

Access HTTP response as string in Go Communication between multiple docker-compose projects Can't access 127.0.0.1 How do I delete virtual interface in Linux? ConnectivityManager getNetworkInfo(int) deprecated Bridged networking not working in Virtualbox under Windows 10 Difference between PACKETS and FRAMES How to communicate between Docker containers via "hostname" java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused) wget: unable to resolve host address `http'

Examples related to port

Docker - Bind for 0.0.0.0:4000 failed: port is already allocated How do I kill the process currently using a port on localhost in Windows? Node.js Port 3000 already in use but it actually isn't? Can't connect to Postgresql on port 5432 Spring Boot - How to get the running port Make docker use IPv4 for port binding How to change the default port of mysql from 3306 to 3360 Open firewall port on CentOS 7 Unable to launch the IIS Express Web server, Failed to register URL, Access is denied XAMPP Port 80 in use by "Unable to open process" with PID 4

Examples related to command-prompt

CMD command to check connected USB devices How do I kill the process currently using a port on localhost in Windows? PowerShell The term is not recognized as cmdlet function script file or operable program open program minimized via command prompt How to connect to SQL Server from command prompt with Windows authentication How to see the proxy settings on windows? How do I type a TAB character in PowerShell? Batch file to split .csv file Aliases in Windows command prompt Change all files and folders permissions of a directory to 644/755