Results 1 to 6 of 6
Is there anyway to detect if the network cable is plugged in or if was pulled out? It can be done in Windows, but I haven't found any documentation for ...
- 08-31-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 9
Detecting network cable
Is there anyway to detect if the network cable is plugged in or if was pulled out? It can be done in Windows, but I haven't found any documentation for it on Linux. I looked around in the proc directory to see if it provided any useful information about this, but I didn't come up with anything. Any help would be greatly appreciated.
btw: I'm posting this in the programming section cause I will be needing this info in a program I'm writing.
- 08-31-2007 #2Linux Newbie
- Join Date
- Dec 2005
- Location
- Toronto
- Posts
- 127
Would you mind if I asked you how do you do it in windoz ?
- 08-31-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
what programming language?
if it is bash script then you could use the command 'ethtool interface' and then parse the output.
- 08-31-2007 #4Just Joined!
- Join Date
- Aug 2007
- Posts
- 9
You can use the Win32_NetworkConnection class. Windows also has a Notification Service API but I've never used it.
- 08-31-2007 #5Just Joined!
- Join Date
- Aug 2007
- Posts
- 9
- 08-31-2007 #6Just Joined!
- Join Date
- Aug 2007
- Posts
- 9
I'm just gonna write an update here in case anyone ever runs into this issue in the future.
In proc/, the kmsg file is updated with certain messages. When a network cable is plugged or unplugged, a message will be written there saying eth0: link down or eth0: link down. So you could check this every so often, although the buffer is only 4096bytes, so if you don't check for a while, or there are too many messages, you might miss it.
You can also look at proc/net/bonding which will also give you a status. This is a bit nicer because you can look at it anytime and it will have the most updated info unlike the kmsg which is basically a rolling log. Unfortunately you have to enable certain options when building the kernel in order to get the bonding directory. So if you don't have it right now, you'll have to either rebuild the kernel or use kmsg.


Reply With Quote
