Python - Outgoing Bandwidth For Public Ips
I am using the below line of code to check the total bytes sent out of my centos box import psutil psutil.net_io_counters().bytes_sent I want to perform this just for the public I
Solution 1:
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
pass
Post a Comment for "Python - Outgoing Bandwidth For Public Ips"