giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.28k stars 1.39k forks source link

Provide more info on net_if_stats() #922

Open giampaolo opened 8 years ago

giampaolo commented 8 years ago

ifconfig command shows more info than we do. It looks like we can add this info in net_if_stats. Since these info may change between platforms it looks like we may provide this as a command separate string, similar to https://pythonhosted.org/psutil/#psutil.disk_partitions, so something like:

snicstats(isup=True, duplex=0, speed=0, mtu=1500, flags="loopback,multicast,ptp")

Alternatively we can do this with booleans, but that depends on whether what provided by other platforms (especially Windows) is portable enough.

UNIX

From /usr/include/net/if.h we can determine:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365943(v=vs.85).aspx

dzen commented 7 years ago

Anoter improvment could be to add a CAN interface in those info.

osteenbergen commented 4 years ago

Don't know if its included in your proposal for flags, but I would like to see NO-CARRIER and LOWER_UP as well.

Example Linux partial ip addr output:

2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether e8:6a:64:ff:ff:ff brd ff:ff:ff:ff:ff:ff
3: wlp61s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether a0:a4:c5:ff:ff:ff brd ff:ff:ff:ff:ff:ff
    inet 192.168.88.226/24 brd 192.168.88.255 scope global dynamic noprefixroute wlp61s0
       valid_lft 555sec preferred_lft 555sec
    inet6 fe80::c40c:faa1:6f97:66ac/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

psutil.net_if_stats() reports: enp0s31f6: snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=65535, mtu=1500) wlp61s0: snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=1500)

isup is correct, however due to no cable inserted into enp0s31f6 that doesn't mean a network connection is possible.

giampaolo commented 4 years ago

isup is correct, however due to no cable inserted into enp0s31f6 that doesn't mean a network connection is possible.

This has recently been fixed in https://github.com/giampaolo/psutil/issues/1830 / #1831 (isup == True if cable is connected).

PicoGeyer commented 2 years ago

It would be nice to have the old IFF_UP flag that the older version of the library reported as isup. It seems to me that there has been some information loss. We used to be able to tell if an interface is administratively up by looking at the isup field and then assuming that if the interface had sane values for duplex and link speed that it must be link up as well.

If I'm not mistake in the new version there is no way to tell the difference between admin down and link down. So having those fields would be really useful to us.