Go Premium for a chance to win a PS4. Enter to Win

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,670 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
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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

783 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