in reply to cleanest/most efficient way to do this

Sorry for taking so long to get back to you on your code. My job got the best of me yesterday and I didn't get home until 1AM. But, without further ado, here's the updated code.
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);
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).

Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com

Replies are listed 'Best First'.
Re: Re: cleanest/most efficient way to do this
by RayRay459 (Pilgrim) on Jan 28, 2002 at 23:43 UTC
    Necos,
    Thnx for taking the time to write the code. It is greatly appreciated. That's a cool way to get ip info and check to see if its alive. i would have never thought to do that. Guess that's one of the coolest things about Perl..... there are so many ways to do something. :)
    Thnx again.
    Ray