Solved

How To Know If Ethernet Cable Is Attached

Posted on 2007-04-03
9
397 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
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
 
LVL 48

Expert Comment

by:Tintin
ID: 18847620
or

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

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

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…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

22 Experts available now in Live!

Get 1:1 Help Now