TIMTOWTDI.
Undefine %status and %service_list at the end of your loop after you've
printed the results fir the current loop. "undef %status".
Or empty them at the end of your loop rather than undefine them so that Perl
doesn't have to do the memory mgmt when they are redefined. "%status = ();
Or do not define them globally but rather within the ADDRESSLOOP label at
the beginning.
"ADDRESSLOOP: foreach (@addresses)
{
my %status = ();
.....
HTH
Trevor Joerges
----- Original Message -----
From: "Raymond Forbes" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 24, 2003 2:54 PM
Subject: Win32::Service problems.
> I am trying to write a script to go through a class c network and find all
> instances of a virus. Below is my code. The problem I am experiencing is
I
> am not getting back accurate information. My best guess is %service_list
> and %status need to be initialized because they seem tobe "holding on" to
> the previous loops information. Anybody have any ideas?
>
> For a bit more information. Everytime this script succesfully connects to
a
> remote machine it responds that it found the virus and the service is
turned
> off. Now this is true for the FIRST machine it runs across, but not the
> others.
>
> Oh, I am using perl 5.8.0
>
> use strict;
> use Net::Ping;
> use Win32;
> use Win32::Service;
>
> my $p;
> my $host;
> my $network;
> my $i;
> my @addresses;
> my $machine;
> my $test_address;
> my $display_name;
> my $display_name2;
> my %service_list;
> my %status;
> my %list;
> my %state;
>
>
> %state = (
>
> 0 => 'unknown',
> 1 => 'stopped',
> 2 => 'starting',
> 3 => 'stopping',
> 4 => 'running',
> 5 => 'resuming',
> 6 => 'pausing',
> 7 => 'paused',
> );
>
>
>
> $network = "10.34.9";
> $display_name = "WINS Client";
>
> $p = Net::Ping->new ();
>
> print "Populating server list\n\n\n";
> for ($i = 1; $i < 10; $i++)
> {
> $test_address = "$network.$i";
>
>
> if ($p->ping ($test_address))
> {
>
> push (@addresses, $test_address);
> print "address added\n";
> }
>
> }
>
> print "Starting Virus Check\n\n\n\n";
> ADDRESSLOOP: foreach (@addresses)
> {
>
> $machine = "\\\\$_";
>
> print "Starting Check of $machine\n";
> if (Win32::Service::GetServices ($machine, \%service_list))
> {
>
> print "Succesfully Connected\n";
>
> }
> else
> {
> print "Could not Connect\n\n\n";
> next ADDRESSLOOP;
> }
>
> if (defined $service_list{$display_name})
> {
>
> print "virus found, the service $display_name is
on
> the machine\n checking status\n";
>
>
>
> Win32::Service::GetStatus ($machine,
> $service_list{$display_name}, \%status);
>
>
>
> print "The virus is
> $state{$status{CurrentState}}\n\n\n";
>
>
>
>
>
> }
> else
> {
>
> print "This machine does not have the
Virus\n\n\n";
>
> }
> }
>
> _______________________________________________
> Perl-Win32-Admin mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs