use warnings; use threads; use threads::shared; use Net::Ping; use Switch; use Net::DNS; use Win32::OLE qw(in with); use Carp; use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; $Win32::OLE::Warn = 3; print "Starting main program\n"; open FILE, "c:\\serverping.txt" or die "could not open the file"; my @lines = ; $linecount = scalar @lines; $row = 0; $line =$lines[$row]; $line =~ s/^\s+//m; $line =~ s/\s+$//m; $mainparam = $row.':'.$lines[$row]; $thr0 = threads->new(\&GetTimeZone, $mainparam); $row++; $mainparam = $row.':'.$lines[$row]; $thr1 = threads->new(\&GetTimeZone, $mainparam); $row++; while(1){ if ($thr0->is_joinable()) { $thr0->join; if ($row<$linecount){ $mainparam = $row.':'.$lines[$row]; $thr0 = threads->new(\&GetTimeZone, $mainparam); $row++; } } if ($thr1->is_joinable()) { $thr1->join; if ($row<$linecount){ $mainparam = $row.':'.$lines[$row]; $thr1 = threads->new(\&GetTimeZone, $mainparam); $row++; } } $thread_count = threads->list(); #print "$thread_count \n"; last if ($row==$linecount && $thread_count == 0); } print "End of main program\n"; close FILE; sub GetTimeZone { my $paramsub = shift; my @subparam = split(/:/, $paramsub); my $subrow = $subparam[0]; my $subhost = $subparam[1]; $subhost =~ s/^\s+//m; $subhost =~ s/\s+$//m; # Create a new ping object $pingit = Net::Ping->new("icmp"); my $timeout = 10; print "\n$subrow \t $subhost \n"; my $user="domain\\username"; my $pwd="password"; my $locatorObj =Win32::OLE->new("WbemScripting.SWbemLocator") or die "ERROR CREATING OBJ"; $locatorObj->{Security_}->{impersonationlevel} = 3; if( $pingit->ping($subhost, $timeout) ) { print "Host ".$subhost." is alive\n"; eval { my $objWMIService = $locatorObj->ConnectServer($subhost, "root\\cimv2", $user, $pwd); if (Win32::OLE->LastError()) { print "$_\n"; Win32::OLE->LastError(0); # this clears your error } else { $colItems = $objWMIService->ExecQuery ("Select * from Win32_Timezone","WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly); if (Win32::GetLastError()) { print "$subhost : $_\n"; Win32::OLE->LastError(0); # this clears your error } else{ foreach my $objItem (in $colItems) { print "\n$subhost \t $objItem->{StandardName} \t $objItem->{Caption} \t $objItem->{Description} \n"; } } } }; if ($@) { print "Warning: Error querying object $subhost: $@\n"; } } else { print "Warning: ".$subhost." appears to be down or icmp packets are blocked by their server\n"; } $pingit->close(); }