如何在 Windows 7 上使用 Python 计算网络使用情况?
我将如何编写一个 python 脚本来显示 Windows 7 计算机上正在使用多少带宽以及正在传输多少数据?
How would I go about writing a python script that shows how much bandwidth is being used and how much data is being transferred on a Windows 7 machine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从技术上讲,您想要的不是您所使用的语言的问题 - 在网络接口上传输的数据量是您需要从操作系统或网络设备驱动程序获取的数据。获取这些统计信息的方式会根据操作系统的不同而有所不同,因此这是您首先需要确定的。
What you want technically isn't a problem of the language you're using - how much data is being transferred on your network interfaces is something you need to get from your operating system or network device driver. The way that you acquire these statistics will vary based on the OS, so that's what you need to nail down first.
我发现了一个不错的实用程序,名为 PSUtil。执行调用:
psutil.network_io_counters(pernic=False)
您将能够获取系统网络的总使用情况。然后您可以解析它返回的字符串以获取实际数据。I found a nice utility called PSUtil. Performing the call:
psutil.network_io_counters(pernic=False)
you will be able to get the total system network usage. You can then parse the string it returns to get the actual data.首先,这取决于您当前使用的Python版本。
如果您使用 v2.6.5,您可能需要查看此处。
Firstly, it depends on which version of Python you are currently using.
If your using v2.6.5, you might want to check here.