Solved

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

Posted on 2001-08-02
6
2,649 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 200 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what does getent do 3 50
Embeded Linux on Router 9 106
Problem to run file 9 118
Use Powershell script to ftp 10 102
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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