Getting hard drive serial number from USB devices
Madison Kelly
linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Sat Jan 14 18:44:45 UTC 2006
For the record/interest, here is the code that gets the IDE hard
drive's serial number:
-=-=-=-=-
#!/usr/bin/perl
use strict;
use warnings;
use FileHandle;
my $dev="hda";
my $read_id = new FileHandle;
if ( $read_id->open("< /proc/ide/$dev/identify") )
{
print "This appears to be an IDE disk.\n";
}
else
{
die "I can't read any devices for: [$dev]\n";
}
<$read_id>;
my $sn = substr(<$read_id>,10,29).substr(<$read_id>,0,20);
$sn=~s/2020//g;
$sn =~ s/\ //g;
my $serial;
$serial.=chr(hex $_) foreach (unpack("a2" x 20,$sn));
print "The serial number of device: [$dev] is: [$serial].\n";
$read_id->close;
exit(0);
-=-=-=-=-
Sample output:
# ./test.pl
This appears to be an IDE disk.
The serial number of device: [hda] is: [3LF00S4C].
-=-=-=-=-
I am not sure how reliable it is to use '/proc' though... I have a
vague recollection that '/proc' was being phased out? If possible, I'd
rather query a device directly.
Madison
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Madison Kelly (Digimer)
TLE-BU; The Linux Experience, Back Up
Main Project Page: http://tle-bu.org
Community Forum: http://forum.tle-bu.org
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list