查看端口或者进程命令(netstat & lsof)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查看端口或者进程命令(netstat & lsof)相关的知识,希望对你有一定的参考价值。

参考技术A 1 仅限 Linux

netstat  -anp  |grep  270/docker  查看端口/应用 有没有被用

-a 或–all 显示所有连线中的Socket。

-t 或–tcp 显示TCP 传输协议的连线状况。

-n 或–numeric 直接使用IP地址,而不通过域名服务器

grep 命令用于查找文件里符合条件的字符串。

2 仅限mac

如果需要查询inet,netstat -anvf inet        netstat -anvf  inet | grep 9000

如果需要查询TCP, netstat -anvp tcp        netstat -anvp tcp | grep 9000

lsof -i -P -n | grep 8080  ( -n no host names   -P no port names )

lsof -i:8080 (-i表示端口)

lsof -i tcp:8080 查看8080端口的TCP情况

3 Mac and Linux

ps -ef | grep docker/9000  (-e 显示所有进程。-f 全格式)

其实最好用的是help,    netstat -h,哈哈 。

命令行查看端口

 

1.列出所有端口的情况

  netstat -ano

 

2.查看端口为8080的占用情况 ,最后一位为PID

  netstat -ano|findstr 8080

a.查看是哪个进程或者程序占用了8080端口,即PID为11348的进程,结果是:java.exe

  tasklist|findstr "11348"

 

b.

 

3.强制关闭PID为6820的进程

  taskkill /pid 11348  /F

 

4.查看帮助

 

 

 

 

以上是关于查看端口或者进程命令(netstat & lsof)的主要内容,如果未能解决你的问题,请参考以下文章

命令行查看端口

Linux 查看端口占用情况

查看windowde 进程的命令

cmd查看端口占用,查看进程,并结束进程的方法(window版本)

Linux系统之查看进程监听端口方法

查看进程-查看端口占用-杀进程