Solved

How To Know If Ethernet Cable Is Attached

Posted on 2007-04-03
9
395 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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 9

Accepted Solution

by:
kfullarton earned 125 total points
Comment Utility
Try ethtool....

ethtool eth0
0
 

Author Comment

by:cunningham
Comment Utility
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
Comment Utility
ethtool | grep -i link will tell you if the link is up or down from the local machine.
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
or

mii-tool eth0 | grep -q "link ok"  || echo "eth0 is down"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:cunningham
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now