Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get link speed programmatically?

Tags:

linux

udev

I am writing an application that reports attributes of network devices on the local machine. I need the mac address, mtu, link speed and a few others. I'm using udev for this. I've already figured out how to get the mac address and mtu, but not how to get the link speed. I can get it with ethtool from the terminal, but I need a way to get it programmatically.

Does anyone know how I can get the link speed attribute with udev or another library?

like image 997
StackedCrooked Avatar asked May 20 '10 08:05

StackedCrooked


1 Answers

You can get the link speed in bit per second using the sysfs interface:

cat /sys/class/net/eth0/speed
1000
like image 184
yadutaf Avatar answered Oct 26 '22 02:10

yadutaf