Reputation: 313
What is the preferred and cross-platform (Ubuntu, Redhat) way to get supported interface link speed?
i am familiar with ethtool, but i would like an option not to use an external tool, but only python.
Upvotes: 3
Views: 2782
Reputation: 122
Until something better is invented you can use this on Linux:
with open(f'/sys/class/net/<iface-name>/speed') as f:
iface_speed_mbps = int(f.read().strip())
However, it seems not always available.
Upvotes: 1
Reputation: 793
There's actually a python module providing bindings for the ethtool kernel interface. This sound like what you're looking for. See https://github.com/fedora-python/python-ethtool for details.
Upvotes: 3