i want to check if the LAN cable is plugged in on a linux system, is there any file in /sys or /proc that i can check (i would like to do it in C)?
Asked
Active
Viewed 2,453 times
4
-
Possibly see http://stackoverflow.com/questions/4231507/how-to-check-ethernet-in-linux – Stecman Sep 08 '12 at 09:44
-
I just posted a solution @ http://stackoverflow.com/questions/4231507/how-to-check-ethernet-in-linux. Maybe you could use the same. – loxxy Sep 08 '12 at 10:51
2 Answers
5
To check if a cable is plugged you can look in /sys/class/net/
For ex. for eth0 connection:
$ grep "" /sys/class/net/eth0/*
/sys/class/net/eth0/carrier:0
/sys/class/net/eth0/operstate:down
As you can see, cable isn't plugged. if it was plugged i was getting:
/sys/class/net/eth0/carrier:1
/sys/class/net/eth0/operstate:up

Ddorda
- 399
- 1
- 10