in reply to cleanest/most efficient way to do this

To add to the last comment, if you are not using perl 5.6 or higher, the Win32::AdminMisc module written by Dave Roth (which you can get here), as well as the Win32::NetAdmin module have about 90% of the functions you'll need. The only thing either will not do is ping the machines for you, but that's what qx() or the backticks are for (personally, I like qx() more).

Hope that helps some...

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
  • Comment on Re: cleanest/most efficient way to do this

Replies are listed 'Best First'.
Re: Re: cleanest/most efficient way to do this
by Juerd (Abbot) on Jan 26, 2002 at 01:36 UTC

    but that's what qx() or the backticks are for (personally, I like qx() more).

    I understand what you're trying to say, but some beginners reading this might think backticks and qx() are two different things. Backticks and qx() are the same. qx() is an operator, `` is its shorthand. In fact, any non-whitespace character can be used as a delimiter (if it's alphanumeric, whitespace before the delimiter is required). qx() is not a function - my $dir = qx("ls -l") will probably not do what you want.

    `ls -l` qx(ls -l) qx[ls -l] qx`ls -l` qx$ls -l$ qx!ls -l! qx nls -ln
    More info: perlop

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

Re: Re: cleanest/most efficient way to do this
by RayRay459 (Pilgrim) on Jan 26, 2002 at 01:22 UTC
    Necos,
    Thank you for answering my posting. Since i work for a large company and this is for our production environment, they will not let me add a module to the machines with out it being in QA for a month. and even that gets pushed off. here's some of the code i have been using for the pdc dump and ipaddress lookup :
    #!D:\Perl\bin -w use strict; use Win32::NetAdmin; 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 will take a file and read it in and resolve hostname # to ip address ##################################################################### 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>) { my $hostname = $_; chomp $hostname; @addr = gethostbyname($hostname); # note: an array now splice(@addr, 0, 4); # get rid of other stuff foreach (@addr) { print OUT join('.', unpack('C4', $_)) ."\t" . $hostname . "\n" +; } } close(IN); close(OUT);