in reply to parsing windows ipconfig /all

Hello, and than you for the responses

My apologies for not including the code to begin with. I have a script that has 2 option. The first option does not uses and special modules that need to be installed, the 2nd option uses the Win32::IPConfig module.

I am primarily interested to see if there is a better way to maybe rewrite option #1 to make it shorter and more efficient. We are not permitted to install modules that don't already exist on the windows host

use strict; use warnings; use Data::Dumper; # Option 1 my @doms = (); my $line; my $found=0; my $junk; my $searchdom; open my $data, '-|', 'ipconfig /all'; while ($line = <$data>) { if ($line =~ /DNS Suffix Search List/ ) { $found=1; ($junk,$searchdom)=split(/:/, $line); $searchdom =~ s/\s+//g; push(@doms,$searchdom); } elsif ($found && ($line !~ /:/ && $line !~ /^\n/) ) { chomp $line; $searchdom=$line; $searchdom=~ s/\s+//g; push(@doms,$searchdom); } elsif ( $found ) { last; } } close $data; #print "$_\n" foreach(@ips); print Dumper \@doms; # # Option 2 use Win32::IPConfig; my $host = ""; my $ipconfig = Win32::IPConfig->new($host); my @searchlist = $ipconfig->get_searchlist; print Dumper \@searchlist;

Again...thank you in advance

Gary

Replies are listed 'Best First'.
Re^2: parsing windows ipconfig /all
by afoken (Chancellor) on Nov 09, 2023 at 19:53 UTC
    if ($line =~ /DNS Suffix Search List/ ) {.

    As explained and shown, this will fail on almost all Windows versions except for Enlish language versions.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)