1
以特定于Linux的方式,如何获得当前在某个接口中接受连接的所有打开的UDP端口和所有TCP端口的列表?如何检索系统中使用的端口?
以特定于Linux的方式,如何获得当前在某个接口中接受连接的所有打开的UDP端口和所有TCP端口的列表?如何检索系统中使用的端口?
最常用的方法是用netstat控制台工具具有以下标志:
netstat -plan
其中:
-p : Show the PID and name of the program to which each socket belongs;
-l : Show only listening sockets;
-a : Show both listening and non-listening sockets;
-n : Show numerical addresses instead of trying to determine symbolic host, port or user names.
对于额外的输出选项和标志请检查手册页man netstat
。根据您的特殊需要,只TCP或UDP(例如)协议的连接,可以检查:
netstat -4 --tcp --udp --all
另外,lsof -i
可能会有所帮助。
最有可能你所感兴趣的以下信息(特殊/ proc文件系统):
的/ proc - 挂载点proc文件系统,它可以访问通过下列文件到内核的状态信息:
跨越另一个进程做了这个工作不是我一个可行的解决方案。你知道这些公用设施从哪里获取信息吗? – lvella