Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I get a MAC address and Harddisk serial number in c under linux?

Posted on 2001-08-02
6
Medium Priority
?
2,664 Views
Last Modified: 2007-12-19
I want to write a programmer in c, it can get network card MAC address, and harddisk serial number, How can I do? show me a example is best!
0
Comment
Question by:sandy_wu
[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
  • 4
  • 2
6 Comments
 
LVL 5

Expert Comment

by:bryanh
ID: 6352227
I don't have an example handy, or the time to write one, but let me get you started:

You can get the network card MAC address with a SIOCGIFHWADDR ioctl to any internet socket.  The program 'ifconfig' is a good example of this.  You can get the hard disk serial number, if it is an ATA disk, with a HDIO_GET_IDENTITY ioctl.  The program 'hdparm' is a good example of this.

A more modern and possibly easier way to get the disk serial number is from the file /proc/ide/hda/identity, where it is an ASCII string starting with the 20th byte.

Of course, you might also just call Ifconfig and Hdparm, especially if you can use a high level language instead of C.
0
 

Author Comment

by:sandy_wu
ID: 6358020
Hello bryanh:

   thank U! please tell me where can i find "hdparm" and "ifconfig", are they c source code?
   In /proc/ide/hda/identity, how much bytes should the serial have?

   thanks very much!

   
   
0
 

Author Comment

by:sandy_wu
ID: 6358109
Hello bryanh:

   thank U! please tell me where can i find "hdparm" and "ifconfig", are they c source code?
   In /proc/ide/hda/identity, how much bytes should the serial have?

   thanks very much!

   
   
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:sandy_wu
ID: 6358116
Hello bryanh:

I have used the "hdparm -I /dev/hda1", but the serial result seem not equal to the bytes in proc/ide/hda/identity, why?  

thanks again!
0
 
LVL 5

Accepted Solution

by:
bryanh earned 800 total points
ID: 6358290
As with any respectable Linux software, you can find Hdparm and Ifconfig on www.freshmeat.com.  Ifconfig is part of the "net-tools" package; Hdparm is a package unto itself.  The source code is C.

The serial number in /proc/ide/hda/identify is 20 bytes.

In re hdparm -I not being the same as /proc/ide/hda/identify:  I see this too, and my guess is that Hdparm or the Linux ioctl is uses is broken.  First of all, hdparm -I reads directly from the disk, whereas /proc/ide/hda/identify shows you information that Linux read from the drive at boot time.  I think Linux knows better than Hdparm how to read the identification data.  Note that hdparm -i tells you what Linux read at boot time and is identical to /proc/ide/hda/identify.

0
 

Author Comment

by:sandy_wu
ID: 6358353
thank U bryanh:
   Although I cant get into www.freshmeat.com, But i still thank you very much!
0

Featured Post

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 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