如何find正在ping本地主机的程序

你怎么能findpinglocalhost进程? 虽然它不是脚本,但ping命令可以简单地从进程表中grep。

我已经使用wireshark,但是找出哪个进程实际上导致了ping是没有帮助的。

非常感谢任何提示。

命令sudo lsof -n |grep "st=07"似乎工作。

为了testing它,我在一个terminal上运行了如下所示的ping来生成ICMP数据包

 arul@cheetah:~$ ping localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.048 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.049 ms 

在另一个terminal上,我运行lsof ,如下所示。 您可以看到输出显示了进程和作为ICMP数据包源的pid。

 arul@cheetah:~$ sudo lsof -n |grep "st=07" ping 3344 arul 3u raw 0t0 602086 00000000:0001->00000000:0000 st=07 

来源: https : //stackoverflow.com/questions/23327689/identify-the-pid-of-process-which-is-transmitting-icmp-packets

你可以用systemtap来完成,它可以监视所有的子系统,所以你不需要在特定的时刻检查系统状态 – 你可以logging事件:

https://sourceware.org/systemtap/SystemTap_Beginners_Guide/useful-systemtap-scripts.html

发送ICMP Echo Request数据包需要root权限。 所以你有两个select:

  • 检查进程表以获取在root帐户上运行的进程,或使用SUID位
  • 检查“ping”过程

示例命令:

 ps aux |grep ping ps aux |grep root |grep -v \\[ 

然后检查第二个命令的所有结果,如果特定的二进制有SUID位:

 ls -l `which dhclient` ls -l `which getty` ls -l `which passwd` ls -l `which ping` 

正如你从权限列表中看到的,第三和第四个程序有SUID位,而第一个和第二个没有。