我使用下面这行代码来检查从centos框中发出的总字节数
import psutil
psutil.net_io_counters().bytes_sent我只想为公网IP执行此操作。换句话说,我只想计算公网IP的出带宽。
发布于 2020-08-20 11:11:43
import ipaddress
import psutil
net = psutil.net_io_counters(pernic=True)
for name, interface in psutil.net_if_addrs().items():
for address in interface:
try:
network = ipaddress.IPv4Network(f'{address.address}\{address.netmask}')
if not network.is_private and not network.is_reserved:
print(net[name].bytes_sent)
break
except ValueError as e:
# these would be eg MAC addresses or similar
passhttps://stackoverflow.com/questions/63497703
复制相似问题