#!/usr/bin/perl -w use strict; use NetQuery; my $nq = new NetQuery; my @list = $nq->get_all_pcs(); for(@list){ if ($nq->is_alive($_)) { printf("%20s \t %20s\n",$_,$nq->get_clock_speed($_)); } } #### package NetQuery; use strict; use Win32::TieRegistry(Delimiter=>"/"); use Socket; use Net::Ping; sub new{ my ($class) = shift; my $self ={}; bless $self, $class; return $self; } #Function: is_alive #Description: #Arguments: Computer Name #Return Value: Boolean true(1) or false(0) sub is_alive{ my $self = shift; my $cpu = shift; my $p = Net::Ping->new('icmp'); return $p->ping($cpu); } #Function: get_ipaddress #Arguments: Computer Name #Return Value: IP address (ie "192.168.0.2") sub get_ipaddr{ my $self = shift; my $cpu = shift; return inet_ntoa(inet_aton($cpu)) } #Function: get_clock_speed #Arguments: Computer Name #Return Value: processor speed(i.e. "450 MHz") sub get_clock_speed{ my $self = shift; my $cpu = shift; my $info= `psinfo \\\\$cpu`; my ($processor)= ($info =~ /Processor\s+speed: \s+? (\d+\.?\d+?\s+\w+) #processor info /sxg); return ($processor || "unknown"); } #Function: get_memory #Arguments: Computer Name #Return Value: amount of availible Memory(i.e. "128 MB") sub get_memory{ my $self = shift; my $cpu = shift; my $info= `psinfo \\\\$cpu`; my ($memory)= ($info =~ /Physical\s+memory: \s+ (\d+\s+\w+) #memory /sxg); return ($memory || "unknown"); } #Function: get_all_pcs #Arguments: none #Return Value: all computers visible on the domain sub get_all_pcs{ my $self = shift; return map{ m|\\+(\w+)| }`net view`; } #Function: get_logged_on #Arguments: Computer Name #Return Value: user currently logged on sub get_logged_on{ my $self = shift; my $cpu = shift; my $log = `psloggedon \\\\$cpu`; my($loggedon) = ($log =~ /locally:\n\s+.*?\b(\w+?)\n/)[0]; return $loggedon || "unknown"; } #Function: get_sp #Arguments: Computer Name #Return Value: Service Pack number sub get_sp { my $self = shift; my $cpu= shift; my $sp = $Registry->{"//$cpu/LMachine/SOFTWARE/" . "Microsoft/Windows NT/CurrentVersion/CSDVersion"}; if( ! $sp || $sp !~ /(\d+)/ ) { return "unknown"; } return $sp; } 1;