Solved

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

Posted on 2001-08-02
6
2,657 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

622 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