[英]How to calculate network usage with Python on Windows 7?
我将如何编写一个Python脚本来显示在Windows 7机器上正在使用多少带宽以及正在传输多少数据?
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.
获取这些统计信息的方式会因操作系统而异,因此首先需要确定这些信息。
I found a nice utility called PSUtil . 我找到了一个名为PSUtil的实用程序。 Performing the call:
psutil.network_io_counters(pernic=False)
you will be able to get the total system network usage. 执行呼叫:
psutil.network_io_counters(pernic=False)
您将能够获得系统的总网络使用率。 You can then parse the string it returns to get the actual data. 然后,您可以解析返回的字符串以获取实际数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.