lve*_*lla 1 linux network-programming
在Linux特定的方式中,如何获取所有开放UDP端口的列表以及当前在某个接口中接受连接的所有TCP端口?
最常见的方法是使用带有以下标志的netstat控制台实用程序:
netstat -plan
Run Code Online (Sandbox Code Playgroud)
哪里:
-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.
Run Code Online (Sandbox Code Playgroud)
有关其他输出选项和标志,请查看手册页man netstat.根据您的特定需求,只能检查TCP或UDP(例如)协议连接:
netstat -4 --tcp --udp --all
Run Code Online (Sandbox Code Playgroud)
或者,lsof -i可能会有所帮助.
您最有可能对以下信息感兴趣(特殊/ proc文件系统):
/ proc - proc文件系统的挂载点,通过以下文件访问内核状态信息: