Solved

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

Posted on 2001-08-02
6
2,647 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:sandy_wu
Comment Utility
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
Comment Utility
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
Comment Utility
thank U bryanh:
   Although I cant get into www.freshmeat.com, But i still thank you very much!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

12 Experts available now in Live!

Get 1:1 Help Now