All pastes #721035 Raw Edit

sysinfo

public text v1 · immutable
#721035 ·published 2007-09-30 21:49 UTC
rendered paste body
#!/usr/bin/perl
#
# c1zc0-winInfo.pl - by Michael Smith aka rotor
# Description: Display a little sysinfo on windows
# http://st0rage.org | r0t0r @st0rage.org
# irc.efnet.org @ #c1zc0
#

use strict;
use warnings;
use Getopt::Std;
use Win32;
use Win32::SystemInfo;
use Win32::DriveInfo;

my(%args,$time);

getopts("mpbl:d:", \%args);

# if log option specified open logfile or die 
if($args{l}){ 
	my $logPath = $args{l}; # path to logfile
	open(LOGFILE,">$logPath") # open path to logfile or die
		or die "Couldnt open $logPath for writing run without -l option or specify new logfile\n";
}
# die unless atleast option -b (basic sysinfo) is specified
if($args{b}){ &basic; } else { &usage; }
# if -p (processor info) specified goto processor() 
if($args{p}){ &processor; }
# if -m ( memory info ) specified goto memory()
if($args{m}){ &memory; }
# if -d ( HDD drive info ) specified goto driveinfo()
if($args{d}){ &driveinfo; }
# driveinfo() -  subroutine for disk drive information
sub driveinfo()
{
	if($args{d} eq " "){
		print("You didnt specify a drive letter to check usage on eg ( c ) or ( c: )\n");
		print("Can only print drive letters\n");
		print("Drives in use:\n");
		if($args{l}){
			print(LOGFILE "You didnt specify a drive letter to check usage on eg ( c ) or ( c: )\n");
			print(LOGFILE "Can only print drive letters\n");
			print(LOGFILE "Drives in use:\n");
		}
		my @drives = Win32::DriveInfo::DrivesInUse();
		foreach my $ref (@drives){
			print("Drive Letter: $ref\n");
			if($args{l}){
				print(LOGFILE "Drive Letter: $ref\n");
			}
		}
	} else {
		print("Disk information for: " . $args{d} . "\n");
	}
}
# memory() - subroutine for memory information
sub memory()
{
	my(%memInfo);
	# MB = megabytes change to KB for kilobytes and GB for KB
	if(Win32::SystemInfo::MemoryStatus(%memInfo, "MB"))
	{
		# if logfile option specified print to logfile
		if($args{l}){
		print(LOGFILE "\nMemory Information\n");
		print(LOGFILE "------------------\n");
		print(LOGFILE "Total Physical Memory: " . $memInfo{TotalPhys} . "\n");
		print(LOGFILE "Available Memory: " . $memInfo{AvailPhys} . "\n");
		print(LOGFILE "Memory Load: " . $memInfo{MemLoad} . "\n");
		print(LOGFILE "Size of page (swap) file: " . $memInfo{TotalPage} . "\n");
		print(LOGFILE "Total virtual memory: " . $memInfo{TotalVirtual} . "\n");
		print(LOGFILE "Available virtual memory " . $memInfo{AvailVirtual} . "\n");
		}
		print("\nMemory Information\n");
		print("------------------\n");
		print("NOTE: THIS IS IN MEGABYTES\n");
		print("Total Physical Memory: " . $memInfo{TotalPhys} . "\n");
		print("Available Memory: " . $memInfo{AvailPhys} . "\n");
		print("Memory Load: " . $memInfo{MemLoad} . "\n");
		print("Size of page (swap) file: " . $memInfo{TotalPage} . "\n");
		print("Total virtual memory: " . $memInfo{TotalVirtual} . "\n");
		print("Available virtual memory " . $memInfo{AvailVirtual} . "\n");
		
	} else {
		print("Cant get memory information?");
	}
}
#processor() - subroutine for processor info
sub processor()
{
	my %procInfo;
	if(Win32::SystemInfo::ProcessorInfo(%procInfo))
	{
		# check number of processors then print each processer ( if dual ) and their speed
		for(my $i = 0; $i <$procInfo{NumProcessors}; $i++){
			# if log option specified print to logfile
			if($args{l}){
				print(LOGFILE "\nProcessor Information\n");
				print(LOGFILE "---------------------\n");
				# print speed of processor
				print(LOGFILE "Speed of processor $i: " . $procInfo{"Processor$i"}{MHZ} . "MHz\n");
				# identifier for thr processor as found in registry
				print(LOGFILE "Identifier of processor $i: " . $procInfo{"Processor$i"}{Identifier} . "\n");
				# vendor name of identifier
				print(LOGFILE "Vendor identifier of processor: $i" . $procInfo{"Processor$i"}{VendorIdentifier} . "\n");
				# the name of the processor
				print(LOGFILE "Processor Name of processor: $i" . $procInfo{"Processor$i"}{ProcessorName} . "\n");
			}
			print("\nProcessor Information\n");
			print("---------------------\n");
			print("Speed of processor $i: " . $procInfo{"Processor$i"}{MHZ} . "MHz\n");
			print("Identifier of processor $i: " . $procInfo{"Processor$i"}{Identifier} . "\n");
			print("Vendor identifier of processor: $i" . $procInfo{"Processor$i"}{VendorIdentifier} . "\n");
			print("Processor Name of processor: $i" . $procInfo{"Processor$i"}{ProcessorName} . "\n");
		}
	}
}
# basic() - subroutine for basic sysinfo
sub basic()
{
	my $loginName = Win32::LoginName; # your login name
	my $nodeName = Win32::NodeName; # computers node name
	my $perlVer = Win32::BuildNumber;   # active state build number
	# name of microsoft Network domain that owner of process is logged into
	my $domainName = Win32::DomainName; 
	my $fsType = Win32::FsType; # type of file system
	# this is for time and date long but no fucking module worked
	my @days=("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
	my @months=("January","February","March","April","May","June","July","August","September","October","November","December");
	my($seg,$min,$hora,$dia,$mes,$ano,$wday,$yday,$isdst)=gmtime(time());
	my$year=$ano+1900;
	if($min < 10) { $min="0".$min; }
	if ($hora<12) { $min.=" AM"; }
	my $time="$days[$wday-1], $months[$mes] $dia, $year at $hora:$min";
	# if log option specified print output to logfile and then to screen 
	if($args{l}){
		print(LOGFILE "c1zc0-winInfo - by Michael Smith aka rotor \n");
		print(LOGFILE "Basic System Information\n");
		print(LOGFILE "------------------------\n");
		print(LOGFILE "Script run: $time\n");
		print(LOGFILE "Active State Perl version: $perlVer\n");
		print(LOGFILE "Node Name: $nodeName Login Name: $loginName\n");
		print(LOGFILE "MS Domain name: $domainName FS Type: $fsType\n");
	}
	print("\nc1zc0-winInfo - by Michael Smith aka rotor \n");
	print("Basic System Information\n");
	print("------------------------\n");
	print("Script run: $time \n");
	print("Active State Perl version: $perlVer\n");
	print("Node Name: $nodeName Login Name: $loginName\n");
	print("MS Domain name: $domainName FS Type: $fsType\n");
}
sub usage()
{
	print("\nc1zc0-winInfo - by Michael Smith aka rotor \n");
	print("Description: displays some sysinfo on win32\n");
	print("Usage: perl $0 -b -l [logfile] []\n");
	exit;
}