We can retrieve all network interface cards’ (NIC) information using the psutil
module in Python.
psutil
modulepsutil
(Python system and process utilities) is a Python package that retrieves information on ongoing processes and system usage (CPU, memory, storage, network, and sensors). It is mostly used for system monitoring, profiling, restricting process resources, and process management.
The module can be installed via pip
as follows:
pip install psutil
net_if_stats
methodThe net_if_stats
method retrieves information about each NIC as a dictionary. The key is the NIC name, and the value is a named tuple with the following attributes:
isup
: This is a Boolean value that indicates whether the NIC is up and running.duplex
: This refers to the duplex communication type. The possible values are NIC_DUPLEX_FULL
, NIC_DUPLEX_HALF
, and NIC_DUPLEX_UNKNOWN
.speed
: This is the speed of the NIC expressed in megabits.mtu
: This is the maximum transmission unit of the NIC expressed in bytes.psutil. net_if_stats()
The method has no parameters.
import psutilprint("NIC info:")print(psutil.net_if_stats())
psutil
module.psutil.net_if_stats()
method.