gtfx
gtfx

Reputation: 313

Python interface supported link speed

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

Answers (2)

MiaPlan.de
MiaPlan.de

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

Leon Weber
Leon Weber

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

Related Questions