Python interface supported link speed

Question:

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.

Asked By: gtfx

||

Answers:

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.

Answered By: Leon Weber

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.

Answered By: MiaPlan.de
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.