Raymond Forbes wrote:
> 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
Try my re-formatted version (I think it's important to define your
vrbls where they are needed rather than sticking them all up top).
I switched to icmp for the ping.
use strict;
use Win32;
use Net::Ping;
use Win32::Service;
my %state = (0 => 'unknown', 1 => 'stopped', 2 => 'starting', 3 => 'stopping',
4 => 'running', 5 => 'resuming', 6 => 'pausing', 7 => 'paused');
my $network = '10.34.9';
my $display_name = 'WINS Client';
my $p = Net::Ping->new('icmp', 5);
print "Populating server list\n";
my @addresses;
for (my $i = 1; $i < 10; $i++) {
my $test_address = "$network.$i";
print "ping ($test_address)\n";
if ($p->ping ($test_address)) {
push @addresses, $test_address;
print "$test_address added\n";
}
}
print "Starting Virus Check\n";
foreach (@addresses) {
print "Starting Check of $machine\n";
my $machine = "\\\\$_";
my %service_list;
if (Win32::Service::GetServices ($machine, \%service_list)) {
print "Succesfully Connected\n";
} else {
print "Could not Connect\n";
next;
}
if (defined $service_list{$display_name}) {
print "virus found, the service $display_name is on the " .
"machine\n checking status\n";
my %status;
Win32::Service::GetStatus ($machine,
$service_list{$display_name}, \%status);
print "The virus is $state{$status{CurrentState}}\n";
} else {
print "This machine does not have the Virus\n";
}
}
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs