How to check ethernet link speed in TypeScript on Linux

On Linux, the kernel exposes the negotiated link speed of a network interface at /sys/class/net/<iface>/speed (in MBit/s). This post shows a minimal TypeScript class that reads that file and reports whether the interface is connected at gigabit speed or slower.

Usage example

The check is ok at 1000 MBit/s or faster and warning below that — useful to detect a cable or switch problem that silently downgraded a link to 100 MBit/s:

Note that reading the speed sysfs file fails with EINVAL when the interface is up but has no carrier, so an unplugged cable is reported as an error rather than a parsed value.


Check out similar posts by category: TypeScript Linux Networking