Solved

How To Know If Ethernet Cable Is Attached

Posted on 2007-04-03
9
402 Views
Last Modified: 2008-01-09
I am looking for a way to programmatically tell whether an active ethernet cable is attached to my Linux system. I am running Mandrake Linux, but would like a Linux-neutral solution if there is one. Is there a way to know (programmatically) whether the ethernet port on my Linux system has a cable attached (assuming that the other end of the cable is attached to an active, running ethernet port)?

Thanks,
Dan
0
Comment
Question by:cunningham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 9

Accepted Solution

by:
kfullarton earned 125 total points
ID: 18846103
Try ethtool....

ethtool eth0
0
 

Author Comment

by:cunningham
ID: 18846326
I think that ethtool is kind of like the thing that I want. I want to be able to do this programmatically, meaning that I want to write a program that checks for ethernet connection activity. How do I do this in a program?
0
 
LVL 9

Expert Comment

by:kfullarton
ID: 18847094
ethtool | grep -i link will tell you if the link is up or down from the local machine.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Tintin
ID: 18847620
or

mii-tool eth0 | grep -q "link ok"  || echo "eth0 is down"
0
 

Author Comment

by:cunningham
ID: 18850273
I am looking for a way to do this inside a program that I write using the 'C' language. I am not interested in how to do this from the shell (unless it leads me to a way to do it in a program!).
0
 
LVL 2

Assisted Solution

by:mostenscer
mostenscer earned 125 total points
ID: 18854182
Well i hope you know that u can run shell Programs through C programming languages The systax is like
system("ls -la");
you may have to include system.h or so
ofter than u can write the out put to a file and then start readind it from the tail and so on ...................
0
 

Author Comment

by:cunningham
ID: 18857164
I thought that there would be some kind of intrinsic call that I could make without using the 'system' call, but it doesn't look like there is. I'll split the points because it looks like the solution is to use a shell command within the 'system' call.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18878938
There's no specific system call you can make as it is dependant on many different things.

Have a look at the source of ethtool to get an idea of how to program it in C.
0
 
LVL 2

Expert Comment

by:mostenscer
ID: 18879129
well well come to be world of c:) dowload this pieace of code and read the documention and you will get the answer
http://0pointer.de/lennart/projects/ifplugd/
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question