Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I'm not very experienced with network stuff and was wondering if you could offer any help with this.

Basically I want to script a program that will allow me to specify either a domain name and machine name, or supply an IP address, username, password and confirm password, that will allow me to look at a machine and pull some information off it. This should include OS, OS version, Service packs, CPU type, CPU clock, memory and HD total & free space. Very much like a simple auditing system.

If you could point me in the direction of things I need to look at in order to do this I would be very grateful.

Thank you for all you help,
Kwun Cheung.

  • Comment on Retrieve system info from networked PCs

Replies are listed 'Best First'.
Re: Retrieve system info from networked PCs
by meetraz (Hermit) on Jun 16, 2004 at 17:38 UTC
    Here's something to get you started:

    use strict; use Win32::OLE qw(in); my $host = 'serverABC'; my $username = 'adminaccount'; my $password = 'secret'; my $WMI = Win32::OLE->new('WbemScripting.SWbemLocator'); my $WMIServices = $WMI->ConnectServer($host, 'root/cimv2', $username, +$password) or die ("Could not connect to $host"); $WMIServices->{Security_}->{ImpersonationLevel} = 3; my $os_set = $WMIServices->InstancesOf("Win32_OperatingSystem"); my ($os_name, $os_version, $os_sp); foreach my $os (in($os_set)) { $os_name = $os->{'Caption'}; $os_version = $os->{'Version'}; $os_sp = $os->{'CSDVersion'}; } print "OS = $os_name $os_version $os_sp\n";

    Documentation for other Win32 WMI classes can be found here:

    http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_classes.asp

Re: Retrieve system info from networked PCs
by dba (Monk) on Jun 16, 2004 at 13:31 UTC
    Net::Telnet would be the starting point for unix systems. (if telnet open, otherwise Net::SSH if ssh setup) Based on uname you should issue appropriate commands for the OS to get the information.
    For windows you should probably use Win32 module
    Update:
    You could also check WshRemote and WshNetwork objects of Windows scripting. Is there one ? :)
Re: Retrieve system info from networked PCs
by amw1 (Friar) on Jun 16, 2004 at 15:12 UTC
    Not a perl solution but it sounds like something that nagios will do quite well. www.nagios.org. It will monitor a bunch of different statistics about machines on your network, throw alerts if something breaks and keep a history of what was broken etc. Decent software.
Re: Retrieve system info from networked PCs
by blueAdept (Beadle) on Jun 16, 2004 at 17:26 UTC
    You're question is rather vague.. From the terminology you used in the question I'm guessing you're in a windows environment, wanting to know what type of windows OS a machine is, what service packs it has, etc..

    There are many available options, but a general question deserves a general answer. Look into WMI (Windows Management Instrumentation) - it can be accessed using Win32::OLE. As part of SDK/administration packs from Microsoft there are examples of how to tap WMI from various scripting languages.(including perl)