如何使用本机python执行ping或traceroute? [英] How can I perform a ping or traceroute using native python?

查看:280
本文介绍了如何使用本机python执行ping或traceroute?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从Python内部执行ping和traceroute,而不必执行相应的shell命令,所以我更喜欢本机python解决方案.

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 solution.

推荐答案

出于安全考虑,经常以超级用户身份运行解释器(当然,您确实需要具有超级用户权限才能访问由ping和traceroute的ICMP规范!),但是如果您没有问题,这并不难-例如,

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!

这篇关于如何使用本机python执行ping或traceroute?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆