⑴实例:查看连接某服务端口最多的的IP地址
⑵命令:stat -nat | grep “...:” |awk ‘{print $}’|awk -F: ‘{print $}’|sort|uniq -c|sort -nr|head -
⑶[rootandy ~]# stat -nat | grep “...:” |awk ‘{print $}’|awk -F: ‘{print $}’|sort|uniq -c|sort -nr|head -
⑷[rootandy ~]#
⑸实例:找出程序运行的端口
⑹命令:stat -ap | grep ssh
⑺[rootandy ~]# stat -ap | grep ssh
⑻tcp *:ssh *:* LISTEN /sshd
⑼tcp ::ffff:...:ssh ::ffff:...: ESTABLISHED /
⑽tcp ::ffff:...:ssh ::ffff:...: ESTABLISHED /
⑾tcp ::ffff:...:ssh ::ffff:...: ESTABLISHED /sshd: rootno
⑿unix [ A ] STREAM LISTENING / /tmp/ssh-cXIJj/agent.
⒀unix [ ] STREAM CONNECTED /sshd: rootno
⒁unix [ ] STREAM CONNECTED /sshd: rootno
⒂[rootandy ~]#
⒃实例:在 stat 输出中显示 PID 和进程名称
⒄命令:stat -pt
⒅[rootlocalhost ~]# stat -pt
⒆Active Inter connections (w/o servers
⒇Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
⒈tcp ...:ssh ...: ESTABLISHED /
⒉[rootlocalhost ~]#
⒊stat -p 可以与其它开关一起使用,就可以添加 “PID/进程名称” 到 stat 输出中,这样 debugging 的时候可以很方便的发现特定端口运行的程序。
⒋实例:找出运行在指定端口的进程
⒌命令:stat -anpt | grep ‘:’
⒍[rootandy ~]# stat -anpt | grep ‘:’
⒎tcp ::: :::* LISTEN /java
⒏tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒐tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒑tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒒tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒓tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒔tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒕tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒖tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒗tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒘tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒙tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒚tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
⒛tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
①tcp ::ffff:...: ::ffff:...: ESTABLISHED /java
②[rootandy ~]#
③运行在端口的进程id为,再通过ps命令就可以找到具体的应用程序了。
④上面就是Linux中stat命令的用法介绍了,stat命令还可显示与ip协议相关的数据,检测端口的网络连接状态。