Command line for looking at specific port

2019-01-09 22:46发布

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.

11条回答
唯我独甜
2楼-- · 2019-01-09 22:46

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)
查看更多
▲ chillily
3楼-- · 2019-01-09 22:57

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.

查看更多
小情绪 Triste *
4楼-- · 2019-01-09 23:00

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.

查看更多
【Aperson】
5楼-- · 2019-01-09 23:01

Here is the easy solution of port finding...

netstat -na | find "8080"
查看更多
不美不萌又怎样
6楼-- · 2019-01-09 23:01

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
7楼-- · 2019-01-09 23:01
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)

查看更多
登录 后发表回答