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;

In reply to Common Windows Network info by thunders

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.