4

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)?

Stephen Smally
  • 66
  • 1
  • 1
  • 6
  • 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 Answers2

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
2

Run the ifconfig command which will show all the interfaces connected.

P.P
  • 117,907
  • 20
  • 175
  • 238