system hardware information

William F. Acker WB2FLW +1-303-777-8123 wacker at octothorp.org
Sun Nov 11 13:18:14 EST 2001


Hi,

     Here's a hardware inventory program written in Perl.





          HTH.
          Bill


On Sat, 10 Nov 2001, Richard Villa wrote:

> I am wondering if anyone knows of a function under Linux that is simular 
> to the system information function under windowsx that will let the user 
> know what hardware is configured.
> 
> Richard
> 
> 
> 
> _______________________________________________
> Speakup mailing list
> Speakup at braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup
> 
-------------- next part --------------
#!/usr/bin/perl 
#
# Copyright (C) 1998, Larry McVoy (lm at bitmover.com)
# Copyright (C) 1998, 1999, Raju Mathur (raju at linux-delhi.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# hinv v 1.4pre2
#
# Changes:
#	1.0 - 1.1
#	---------
#		Fri Nov 28 14:28:31 IST 1997
#	Added support for IDE disks -- Paul Danset (paul at oz.net), 
#		Fri Nov 28 14:39:30 IST 1997
#	Changed eth scanning routine to explicitely check for an
#	ethernet-style address in the line.
#					-- Raju Mathur (raju at linux-delhi.org)
#		Fri Nov 28 19:02:22 IST 1997
#	1.1-1.1a
#	--------
#	Small screw-up in the eth code fixed. Thanks, Thomas Gebhardt!
#	1.1a-1.2
#	--------
#		Mon Dec  1 12:06:55 IST 1997
#	Added support for sound devices. I've only checked this out on
#	a commercial OSS system, not with the built-in OSS/Linux/Free.
#	I'm no hotshot Perl programmer, so if the code looks ugly it's
#	your aesthetics which are to blame :-)
#
#	1.2-1.3
#	-------
#	Memory-handling code improvements
#	Floppy code changes
#
#	1.3-1.4pre2
#	-------
#		Tue Jul 20 20:24:03 IST 1999
#	The OSS changes work fine on OSS included in the kernel.
#	Changed the IDE code around:
#		- No more duplicate IDE's
#		- Use a hash instead of an array
#		- Change to give more verbose output
#	CPU code changed to handle new 2.2.x /proc/cpuinfo style
#	Sound code changed to use /proc/sound (doesn't automatically
#		load sound drivers).
#	Display parallel ports from /proc/parport/*
#	Get memory info from /proc/meminfo rather than dmesg (which
#		scrolls around)
#	Larry has agreed to to GPL the code... Eyahooo!
#
#	1.4pre1 - 1.4pre2
#	-----------------
#		Sat Sep 11 09:14:24 IST 1999
#	Added support for ALSA sound devices (/proc/asound/sndstat)
#
#	There may still be problems in the CPU counting code.  Please
#	send samples of /proc/cpuinfo and hinv output for multi-CPU
#	systems.
#					-- Raju Mathur (raju at linux-delhi.org)
#
# Author:		Larry Mcvoy (lm at bitmover.com)
#
# Maintainer:		Raju Mathur (raju at linux-delhi.org)
#
# Try and emulate SGI's hinv command
# We want to figure out the following:
# CPU type, mhz, memory, busses, floppies, disks, tapes, cdroms, ttys,
# networks, graphics, sound

# indy ~ hinv
# Iris Audio Processor: version A2 revision 4.1.0
# 1 175 MHZ IP22 Processor
# FPU: MIPS R4000 Floating Point Coprocessor Revision: 0.0
# CPU: MIPS R4400 Processor Chip Revision: 6.0
# On-board serial ports: 2
# On-board bi-directional parallel port
# Data cache size: 16 Kbytes
# Instruction cache size: 16 Kbytes
# Secondary unified instruction/data cache size: 1 Mbyte on Processor 0
# Main memory size: 64 Mbytes
# Vino video: unit 0, revision 0
# Integral ISDN: Basic Rate Interface unit 0, revision 1.0
# XPI FDDI controller: xpi0, firmware version 9601221233, SAS
# Integral Ethernet: ec0, version 1
# Integral SCSI controller 0: Version WD33C93B, revision D
#  Disk drive: unit 2 on SCSI controller 0
#  Disk drive: unit 1 on SCSI controller 0
# Graphics board: Indy 24-bit

# i586 ~ hinv
# Main memory size: 255 Mbytes
# 1 GenuineIntel 00/07 processor
# 2 16550A serial ports
# 1 National Semiconductor PC87306 floppy controller
# 1 1.44M floppy drive
# 1 vga+ graphics device
# 1 parallel port:
#   lp0: base 0x378, no irq, no dma, modes SPP,ECP,ECPPS2
# 1 IDE device:
#   /dev/hda: ATAPI 32X CD-ROM drive, 128kB Cache
# 1 ethernet interface
#   eth0: OEM i82557/i82558 10/100 Ethernet
# 1 SCSI disk
#   IBM      DNES-309170Y
#   ESG-SHV  SCA HSBP M6
# Sound devices:
#   1 Audio device
#     MAD16 WSS (82C930) (DUPLEX)
#   1 MIDI device
#     Mad16/Mozart
#   1 Timer
#     System clock
#   1 Mixer
#     MAD16 WSS (82C930)
# PCI bus devices:
#     Ethernet controller: Intel 82557 (rev 5).
#     SCSI storage controller: NCR 53c810 (rev 35).
#     VGA compatible controller: Cirrus Logic GD 5480 (rev 35).
#     PIC: Intel Unknown device (rev 0).
#     ISA bridge: Intel 82371AB PIIX4 ISA (rev 2).
#     IDE interface: Intel 82371AB PIIX4 IDE (rev 1).
#     USB Controller: Intel 82371AB PIIX4 USB (rev 1).
#     Bridge: Intel 82371AB PIIX4 ACPI (rev 2).
#     Host bridge: Intel Unknown device (rev 3).
#     Host bridge: Intel Unknown device (rev 2).
#     Host bridge: Intel Unknown device (rev 2).
#     SCSI storage controller: NCR 53c896 (rev 1).
#     SCSI storage controller: NCR 53c896 (rev 1).

$memsize = ( stat "/proc/kcore" ) [7] || die "Cannot stat /proc/kcore" ;
# Use only int portion of the result on converting to MB.
printf "Main memory size: %d Mbytes\n" , $memsize / 1024 / 1024 + .5 ;
open(FD, "dmesg|") || die "no dmesg";
while (<FD>) {
    @_ = split;
    if (/^tty/) {
	$ttys{$_[$#_]}++;
    } elsif (/^Floppy/) {
	$floppyRE = "fd[0-9] is ([0-9.MGKB]*)" ;
	while ( /$floppyRE/o )
	{
	    $floppy{$1}++ ;
	    s/$floppyRE// ;
	}
    } elsif (/^FDC /) {
	s/.*is a //;
	chop;
	$fdc{$_}++;
    } elsif (/^scsi : detected/) {
	$scsi = $_;
    } elsif (/^eth\d.* at .*:..:..:..:..:.*/) {
	s/\s*at .*//;
	push(@eth, $_);
    } elsif (/^(hd[a-z]).*, /) {
	$idedev=$1 ;
	s/.*:\s*//;
	$ide{$idedev} = $_ ;
    } 
}
open(FD, "/proc/cpuinfo");
while (<FD>) {
        @_ = split /\s*:\s*/;
        if (/model name/) {
                $cpu = $_[$#_];
		chomp $cpu ;
		$cpus{"$vendor $cpu"}++;		
        }
        if (/vendor/)
	{
	    $vendor = $_[$#_] ;
	    chomp $vendor ;
        }
}
open(FD, "/proc/ioports");
while (<FD>) {
        if (/kbd/) {
                $kbd++;
        } elsif (/vga/) {
                @_ = split;
                $graphics{$_[$#_]}++;
        }
}

close FD ;
foreach $port ( </proc/parport/*> )
{
    open FD , "$port/hardware" ;
    $str = "" ;
    while ( <FD> )
    {
	@_ = split /\s*:\s*/ ;
	chomp $_[$#_] ;
	$str .= ", " if $. != 1 ;
	if ( $_[$#_] eq "none" )
	{
	    $str .= "no $_[0]" ;
	}
	else
	{
	    $str .= "$_[0] $_[$#_]" ;
	}
    }
    $nlp++ ;
    close FD ;
    $lp{chop $port} = $str ;
    undef $str ;
}

print $mem if (defined $mem);
foreach $key (keys %cpus) {
        print "$cpus{$key} $key processor";
        print $cpus{$key} > 1 ? "s\n" : "\n";
}
foreach $key (keys %ttys) {
        print "$ttys{$key} $key serial port";
        print $ttys{$key} > 1 ? "s\n" : "\n";
}
foreach $key (keys %fdc) {
        print "$fdc{$key} $key floppy controller";
        print $fdc{$key} > 1 ? "s\n" : "\n";
}
foreach $key (keys %floppy) {
        print "$floppy{$key} $key floppy drive";
        print $floppy{$key} > 1 ? "s\n" : "\n";
}
foreach $key (keys %graphics) {
        print "$graphics{$key} $key graphics device";
        print $graphics{$key} > 1 ? "s\n" : "\n";
}
if (defined $kbd) {
        print "$kbd keyboard";
        print $kbd > 1 ? "s\n" : "\n";
}
if ( $nlp )
{
    printf "$nlp parallel port%s:\n" , $nlp == 1 ? "" : "s" ;
}
foreach $keys (sort keys %lp )
{
    print "  lp$keys: $lp{$keys}\n" ;
}
@ide = sort keys %ide ;
if ($#ide > -1) {
        $n = $#ide + 1;
        print "$n IDE device";
        print $n > 1 ? "s:\n" : ":\n";
        foreach $ide (@ide) {
                print "  /dev/$ide: $ide{$ide}";
        }
}
if ($#eth > -1) {
        $n = $#eth + 1;
        print "$n ethernet interface";
        print $n > 1 ? "s\n" : "\n";
        foreach $eth (@eth) {
                print "  $eth";
        }
}
if (defined $scsi) {
        $scsi =~ s/.*detected //;
        $scsi =~ s/ total.//;
        print $scsi;
        open(FD, "/proc/scsi/scsi");
        $_ = <FD>;
        while (<FD>) {
                next unless /Vendor/;
                s/.*Vendor:\s*//;
                s/\s*Rev:.*//;
                s/Model:\s*//;
                print "  $_";
        }
}
#
# Sound code added by Raju Mathur (raju at linux-delhi.org)
#
if ( open ( FD , "/proc/sound" ) || open ( FD , "/proc/asound/sndstat" ) )
{
    $done = 0 ;
    while ( <FD> )
    {
	if ( ! $done )
	{
	    print "Sound devices:\n" ;
	    $nAudiodev = 0 ;
	    $nSynthdev = 0 ;
	    $nMIDIdev = 0 ;
	    $nTimer = 0 ;
	    $nMixer = 0 ;
	    $done = 1 ;
	}
	if ( /^Audio devices:/ )
	{
	    while ( <FD> )
	    {
		if ( /^$/ )
		{
		    goto break1 ;
		}
		s/^[0-9]*:\s*// ;
		push @Audiodev , $_ ;
		$nAudiodev++ ;
	    }
	  break1:
	}
	if ( /^Synth devices:/ )
	{
	    while ( <FD> )
	    {
		if ( /^$/ )
		{
		    goto break2 ;
		}
		s/^[0-9]*:\s*// ;
		push @Synthdev , $_ ;
		$nSynthdev++ ;
	    }
	  break2:
	}
	if ( /^Midi devices:/ )
	{
	    while ( <FD> )
	    {
		if ( /^$/ )
		{
		    goto break3 ;
		}
		s/^[0-9]*:\s*// ;
		push @MIDIdev , $_ ;
		$nMIDIdev++ ;
	    }
	  break3:
	}
	if ( /^Timers:/ )
	{
	    while ( <FD> )
	    {
		if ( /^$/ )
		{
		    goto break4 ;
		}
		s/^[0-9]*:\s*// ;
		push @Timer , $_ ;
		$nTimer++ ;
	    }
	  break4:
	}
	if ( /^Mixers:/ )
	{
	    while ( <FD> )
	    {
		if ( /^$/ )
		{
		    goto break5 ;
		}
		s/^[0-9]*:\s*// ;
		push @Mixer , $_ ;
		$nMixer++ ;
	    }
	  break5:
	}
    }
    if ( $nAudiodev )
    {
	printf ( "  %d Audio device%s\n" , $nAudiodev ,
		$nAudiodev > 1 ? "s" : "" ) ;
	while ( $val = shift @Audiodev )
	{
	    print "    $val" ;
	}
    }
    if ( $nSynthdev )
    {
	printf ( "  %d Synth device%s\n" , $nSynthdev ,
		$nSynthdev > 1 ? "s" : "" ) ;
	while ( $val = shift @Synthdev )
	{
	    print "    $val" ;
	}
    }
    if ( $nMIDIdev )
    {
	printf ( "  %d MIDI device%s\n" , $nMIDIdev ,
		$nMIDIdev > 1 ? "s" : "" ) ;
	while ( $val = shift @MIDIdev )
	{
	    print "    $val" ;
	}
    }
    if ( $nTimer )
    {
	printf ( "  %d Timer%s\n" , $nTimer , $nTimer > 1 ? "s" : "" ) ;
	while ( $val = shift @Timer )
	{
	    print "    $val" ;
	}
    }
    if ( $nMixer )
    {
	printf "  %d Mixer%s\n" , $nMixer , $nMixer > 1 ? "s" : "" ;
	while ( $val = shift @Mixer )
	{
	    print "    $val" ;
	}
    }
}

open(FD, "/proc/pci");
$done = 0;
while (<FD>) {
        if (/^\s*Bus/) {
                if ($done == 0) {
                        print "PCI bus devices:\n";
                        $done++;
                }
                $_ = <FD>;
                print;
        }
}


More information about the Speakup mailing list