Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more info on net_if_stats() #922

Open
giampaolo opened this issue Oct 15, 2016 · 4 comments
Open

Provide more info on net_if_stats() #922

giampaolo opened this issue Oct 15, 2016 · 4 comments

Comments

@giampaolo
Copy link
Owner

giampaolo commented Oct 15, 2016

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:

  • loopback (whether it's a local interface)
  • ptp (whether its a point to point interface)
  • multicast (whether it's a multicast interface)
  • broadcast (whether it's a broadcast interface)

Windows

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

  • description (?)
  • loopback
  • other types (?)
  • status (?)
@dzen
Copy link

dzen commented Jul 26, 2017

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

@osteenbergen
Copy link

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
Copy link
Owner Author

giampaolo commented Sep 30, 2020

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 #1830 / #1831 (isup == True if cable is connected).

@PicoGeyer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants