This goes to show you one of the perks of working on a Win32 system: everything is in the registry if you look hard enough. I tested the code to work under strict, so everyone is happy. Not only that, but I combined finding out the ip and the ping into one step with the registry calls. I've only tested it with one computer, but it should work for you without much tweaking (if at all).use strict; use Win32::NetAdmin; use Win32::Registry; #Yes, I know it's obsolete, but it's so darn cool +! #This is part of the original code... No need to edit this part. open (OUT,">list.txt") || die "Cannot create machine list. :$!"; # This will get the list of machine names from the PDC my @users; Win32::NetAdmin::GetUsers("\\\\Weasel",'',\@users); my @computers = grep { /\$$/ } @users; foreach my $box (@computers) { chop $box; # removes terminal char, must be $ from grep print OUT "$box\n"; # print each $box on a newline } close OUT; #This is the get-ip routine using Win32::Registry #(included in libwin32, so you shouldn't have any problems with instal +ling it). #The logic is: If you can connect to machine remotely, and snag it's i +p, #it's alive and running. In other words, it's a different kind of "pin +g" print "What file do you want to read?"; chomp($InFile = <STDIN>); open(IN,$InFile) || die "Cannot open $InFile: $!"; open(OUT,">results.txt") || die "Cannot create results.txt: $!"; while (<IN>) { chomp; my $remote_obj; my $host = $_; #We need a copy of $_ to log the hostname $main::HKEY_LOCAL_MACHINE->Connect($_, $remote_obj); #Hardwired in +to main:: namespace my $ip_obj; $remote_obj->Open('SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Par +ameters\\Interfaces' , $ip_obj) || print "open key failed\n"; my $regkeys = []; $ip_obj->GetKeys($regkeys); foreach (@$regkeys) { my $temp_obj; my $ip; $ip_obj->Open( "$_", $temp_obj); $temp_obj->QueryValueEx( 'IPAddress' , REG_MULTI_SZ, $ip ); $ip =~ s/^\s//; #Strip out leading whitespace (if at all) $ip =~ s/\s$//; #Strip out trailing whitespace (if at all) print OUT "$ip\t$host\n" if ( not ($ip =~ /^[0]/) ); } } close(IN); close(OUT);
In reply to Re: cleanest/most efficient way to do this
by Necos
in thread cleanest/most efficient way to do this
by RayRay459
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |