How can I perform a ping or traceroute using native python?

后端 未结 7 1680
走了就别回头了
走了就别回头了 2021-01-05 14:56

I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I\'d prefer a native python solutio

7条回答
  •  悲哀的现实
    2021-01-05 15:46

    Running interpreters as root is often frowned upon on security grounds (and of course you DO need to have root permission to access the "raw" socked as needed by the ICMP specs of ping and traceroute!), but if you have no problems with that it's not hard -- e.g., this post gives a workable ping, and Jeremy Hylton's old page has still-usable underlying code for ICMP (both ping and traceroute) though it's written for very old Python versions and needs a litte facelift to shine with modern ones -- but, the concepts ARE all there, in both the URLs I gave you!

提交回复
热议问题