|
From: Josh L. <ru...@us...> - 2003-10-14 00:38:55
|
Update of /cvsroot/acd/acd-1/web/arch/windows-2000
In directory sc8-pr-cvs1:/tmp/cvs-serv14498/web/arch/windows-2000
Added Files:
aging.pl cpu.pl diskspace.pl manual_info.pl memory.pl
network_interfaces.pl
Log Message:
New checkin of tmd's windows stuff.
--- NEW FILE: aging.pl ---
# aging.pl
#
# Author: Trevor Dennison
# October 1, 2003
#
# Gets the date Windows was installed on a machine for ACD
use Win32::TieRegistry( Delimiter=>"/" );
#set the module to return dwords as integers rather than hex strings
$Registry->DWordsToHex(0);
#get the install date (it's actually stored as a unix timestamp...)
$age = $Registry->{"LMachine/Software/Microsoft/Windows NT/CurrentVersion/InstallDate"};
#turn the integer install date into a text string
$textAge = unpack("L", $age);
print "<basic_info>\n";
print " <installed>$textAge</installed>\n";
print "</basic_info>\n";
--- NEW FILE: cpu.pl ---
# cpu.pl
#
# Author: Trevor Dennison
# October 1, 2003
#
# Gets the processor information on a Windows machine for ACD
#
# Note: Right now, the architecture is hardcoded to be i686,
# since there's not an easy way to pull this directly out
# of windows. Plus, anything we are running windows on right
# now is Pentium2 or above, so i686.
use Win32::TieRegistry( Delimiter=>"/" );
#set the module to return dwords as integers rather than hex strings
$Registry->DWordsToHex(0);
#get the processor speed
$speed = $Registry->{"LMachine/Hardware/Description/System/CentralProcessor/0/~Mhz"};
#turn the integer processor speed into a text string
$textSpeed = unpack("L", $speed);
#assume that if we are running windows, this is an i686
#(no good way to pull this out of the system directly.)
$arch="i686";
print "<hostinfo>\n";
print " <cpu speed='$textSpeed' architecture='$arch' />\n";
print "</hostinfo>\n";
--- NEW FILE: diskspace.pl ---
# diskspace.pl
#
# Author: Trevor Dennison
# September 30, 2003
#
# Gets the disk space information on a Windows machine for ACD
use Win32::AdminMisc;
@Drives = Win32::AdminMisc::GetDrives(DRIVE_FIXED);
for $drive (@Drives)
{
($DiskSpace, $Free) = Win32::AdminMisc::GetDriveSpace($drive);
$total += $DiskSpace;
}
$total = $total / (1024 * 1024 * 1024); #get total in GB
$total = int($total); #get rid of decimal portion
print " <basic_info>\n";
print " <diskspace>$total</diskspace>\n";
print " </basic_info>\n";
--- NEW FILE: manual_info.pl ---
#!/usr/local/bin/perl
#
# Collect information from the host that is manually maintained in a
# host specific file. The information file should be in a 'field=value'
# format, one per line.
#
use Win32::OLE;
$info_file="C:\\acd\\acd_manual_info";
if (-f $info_file)
{
open (INFO_FILE, $info_file) || die "Could not open $info_file: $!\n";
print " <hostinfo>\n";
print " <manual_info ";
$gotSerial = 0;
while (<INFO_FILE>)
{
@info = split (/=/);
foreach $value (@info) {chomp $value};
print " $info[0]=\"$info[1]\" ";
if($info[0] eq "serial") { $gotSerial = 1; }
}
# if the serial number was not entered in the manual info file,
# then try to get it from the bios
if($gotSerial == 0)
{
$serial = &getSerialFromBios;
if($serial ne "")
{
print " serial=\"$serial\" ";
}
}
print "/>\n";
print " </hostinfo>\n";
}
close INFO_FILE;
# ---------- getSerialFromBios ----------
# gets the serial number of a machine from the bios. This probably
# only works for dells.
#
# The original code that showed me how to do this was a vb script
# at the following webpage:
# http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/compmgmt/ScrCM41.asp
sub getSerialFromBios
{
my $strComputer = ".";
my $class = "winmgmts:{impersonationLevel=impersonate}!\\\\" . $strComputer . "\\root\\cimv2";
my $objWMIService = Win32::OLE->GetObject($class);
my $colSMBIOS = $objWMIService->ExecQuery("Select * from WIN32_SystemEnclosure");
#not sure if it could actually come back with multiple serial
#numbers, but handle it just in case
my $serialNumber = "";
foreach my $object (in $colSMBIOS)
{
if($serialNumber == "")
{
$serialNumber = $object->{SerialNumber};
}
else
{
$serialNumber = $serialNumber . "," . $object->{SerialNumber};
}
}
$serialNumber;
}
--- NEW FILE: memory.pl ---
# memory.pl
#
# Trevor Dennison
# September 30, 2003
#
# Gets the total physical memory from a Windows machine for ACD
use Win32::AdminMisc;
%Memory = Win32::AdminMisc::GetMemoryInfo();
$Total = $Memory{RAMTotal};
$Total = $Total / (1024 * 1024); #get total memory in MB
$Total = int($Total);
print "<basic_info>\n";
print "<ram>$Total</ram>\n";
print "</basic_info>\n";
--- NEW FILE: network_interfaces.pl ---
# network_interfaces.pl
#
# Trevor Dennison
# September 30, 2003
#
# Gets network interface info from a Windows machine for ACD
@ipconfig = `ipconfig /all`;
$interfaceNum = -1;
$device = "";
$ip = "";
$netmask = "";
$mac = "";
&PrintHeader;
for $line (@ipconfig)
{
$_ = $line;
s/^\s+//;
$line = $_;
if(substr($line, 0, 8) eq "Ethernet")
{
#if this is not the first header line, print the info
#(there is no info to print from before the first header)
if($interfaceNum >= 0)
{
&PrintInfo;
}
$interfaceNum += 1;
$device = "win" . $interfaceNum;
$ip = "";
$netmask = "";
$mac = "";
}
elsif(substr($line, 0, 16) eq "Physical Address")
{
@temp = split(/\s+/, $line);
$mac = $temp[-1];
}
elsif(substr($line, 0, 10) eq "IP Address")
{
@temp = split(/\s+/, $line);
$ip = $temp[-1];
}
elsif(substr($line, 0, 11) eq "Subnet Mask")
{
@temp = split(/\s+/, $line);
$netmask = $temp[-1];
}
}
&PrintInfo;
&PrintFooter;
sub PrintHeader
{
print " <hostinfo>\n";
}
sub PrintFooter
{
print " </hostinfo>\n";
}
sub PrintInfo
{
print " <network_interface interface_device='$device' ip='$ip' netmask='$netmask' hardware_address='$mac' />\n";
}
|