Command line for looking at specific port
Asked Answered
S

18

362

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.

Sacristy answered 17/8, 2012 at 17:45 Comment(1)
netstat is only slow if you don't use the -n switch, which means it has to do lots of DNS lookups.Muscat
S
449

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"
Safe answered 18/6, 2014 at 3:54 Comment(4)
How to use this command? I want to know this port number is working or not link:- [link]( https://.localhost:9043/ibm/console/login.do)Malchus
Also worth mentioning the -o flag (i.e. -nao here) to include the PID of the process using the port.Tisman
if you have any other used port which has "8080" then it will also be grabbed. For example 98080 or 78080 and so onMovable
@Movable As other answers have pointed out, prefixing the port number you are a concerned about with a colon reduces (but does not necessarily eliminate) the possibility of getting false positives. So searching for ":8080" is better than searching for "8080".Fibrilliform
T
116

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.

Tippler answered 17/8, 2012 at 18:3 Comment(0)
R
89

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>
Reconnaissance answered 25/9, 2014 at 4:26 Comment(0)
A
76

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.

Arid answered 9/11, 2013 at 5:36 Comment(1)
Very nice, thanks a lot! Specially for TCP I use following: netstat -o -nap TCP | findstr 0.0:80Lepido
M
24

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 /?
Mesopause answered 23/6, 2014 at 8:47 Comment(0)
P
12
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)

Psid answered 5/11, 2014 at 11:41 Comment(1)
This is not working for windows power shell on windows 2012 R2 and received result as FIND: Parameter format not correctMancini
P
8

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

netstat -an | find "172.20.1.166"
Palpitation answered 18/1, 2021 at 14:14 Comment(0)
T
7

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 *[^ ]*:[^ ]*"
Thibaud answered 23/10, 2017 at 8:30 Comment(0)
D
6

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 .

Dionysus answered 27/4, 2015 at 17:38 Comment(0)
K
6

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
Knob answered 21/8, 2019 at 14:56 Comment(0)
P
3

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.

Perspicuous answered 12/4, 2018 at 4:39 Comment(0)
H
2

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

sudo netstat -tulpn | grep LISTEN | egrep '(8080 |8082 |8083 | etc )'
Holograph answered 23/12, 2019 at 20:32 Comment(0)
B
0

in linux: To find a foreign port you could use:

netstat -anp |grep port|awk '{ print $5 }' |grep port

To find a local port you might use:

netstat -anp |grep port|awk '{ print $4 }' |grep port

Barbrabarbuda answered 7/3, 2022 at 12:49 Comment(0)
P
0

For exact match [windows command prompt]

netstat -aon | findstr "\<5000\>"
Polyp answered 21/12, 2022 at 2:44 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Andalusite
E
0

If you need to check several ports - the simplest way to do it use findstr with several strings for search:

findstr /C:":80 " /C:":443 " /C:":8080"

Spaces after the port numbers are important, without the space findstr will select everything which starts e.g. from ":80". In my case complete command looks like this:

netstat -an | findstr /C:":80 " /C:":443 " /C:":8080"
Erythrocytometer answered 21/2, 2023 at 17:10 Comment(0)
S
0

For me below commands working to check specific port status

netstat -an | find ":8000"

netstat -aon | findstr ":8000"

Smasher answered 2/8, 2023 at 11:39 Comment(0)
R
-2

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)
Ranjiv answered 5/8, 2015 at 13:40 Comment(2)
Minus point because this is not a windows command. If it is available on windows there is no discussion on how to acquire it.Afferent
Does not answer OP's question. -1.Alexandra
A
-3

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

netstat -f 
Anderson answered 13/4, 2014 at 23:6 Comment(1)
The request was to find out if a specific port was in use.Afferent

© 2022 - 2024 — McMap. All rights reserved.