sandy_wu
asked on
How can I get a MAC address and Harddisk serial number in c under linux?
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!
ASKER
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!
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!
ASKER
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!
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!
ASKER
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank U bryanh:
Although I cant get into www.freshmeat.com, But i still thank you very much!
Although I cant get into www.freshmeat.com, But i still thank you very much!
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.