Ever since i learned perl people at my company have been asking me to compile different information on our Network of Windows computers. I've collected a group of subroutines that i use over and over. i finally decided to package all of them together. apologies for lack of pod this is pretty beta.
So far this is all very windows specific and it does shell out to the Ps tools collection of software, so some routines here require that be installed. Also `net view` is called which should be avilible on most windows computers by default.
If anything here can be done via a standard module let me know. I tried to avoid excessive system calls, but was not entirely successful. Since i just grep through the return values from psinfo on some calls, I worry that they may eventually break with another version of that toolkit :(
An example script:
#!/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($_)); } }
And the Module:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Common Windows Network info
by VSarkiss (Monsignor) on Sep 16, 2002 at 18:00 UTC | |
|
Re: Common Windows Network info
by Mr. Muskrat (Canon) on Sep 16, 2002 at 16:39 UTC | |
by charnos (Friar) on Sep 19, 2002 at 15:11 UTC |