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 installing it). #The logic is: If you can connect to machine remotely, and snag it's ip, #it's alive and running. In other words, it's a different kind of "ping" print "What file do you want to read?"; chomp($InFile = ); open(IN,$InFile) || die "Cannot open $InFile: $!"; open(OUT,">results.txt") || die "Cannot create results.txt: $!"; while () { chomp; my $remote_obj; my $host = $_; #We need a copy of $_ to log the hostname $main::HKEY_LOCAL_MACHINE->Connect($_, $remote_obj); #Hardwired into main:: namespace my $ip_obj; $remote_obj->Open('SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\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);