Litherz
Litherz

Reputation: 11

Python Netifaces Network Usage

Apologies in advance if this is a dumb question as I am new to programming.

I have a simple piece of code like this which shows me a list of network interface addresses and their information,

import neitfaces
print(netifaces.interfaces())
user_input = input('Address: ')
print(netifaces.ifaddresses(user_input))

But how do I get the total number of the usage (bytes sent and received) of network interfaces on the computer?

Upvotes: 1

Views: 1238

Answers (1)

marclave
marclave

Reputation: 107

I am not familiar with neitfaces, however, I did a quick google and found some example code that might be of use recieve bytes example.

I also made a sample script your that should work logically, however I did not test it. You need to install the psutil package.

import neitfaces
import psutil

print(netifaces.interfaces())
user_input = input('Address: ')

x = netifaces.ifaddresses(user_input)

data = psutil.net_io_counters(pernic=True)
data = data[x] if type(data) == dict else data
i.rx, i.tx = data[0], data[1]

print(i.rx)
print(i.tx)

This should get you going in the right direction.

Marc

Upvotes: 1

Related Questions