Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

script not finding entire string

Hi guys,

I am working with a perl script that I feed to a file. Then it creates an output

I noticed that values that have multiple IP address dont get captured.

In the master file I have:

};

zone "_msdcs.cvve.foo.edu" in {
      type master;
      file "db.msdcs.cvve.foo.edu";
      allow-update { 128.163.234.17; };
      allow-query { Any; };
      allow-transfer { 128.163.1.6; 128.163.3.10; 128.163.234.17; };
      notify no;
      check-names Ignore;
};

The output I get;

zone _msdcs.cvve.foo.edu allow_update="[128.163.234.17]"
zone _msdcs.cvve.foo.edu allow_transfer="[128.163.1.6]"

as you can see, allow_transfer should of looked like this:

zone _msdcs.cvve.foo.edu allow_transfer="[128.163.1.6,128.163.3.10,128.163.234.17]"

I will post the script on the next thread.

Thanks in advance for you help !

Rich
0
richsark
Asked:
richsark
  • 9
  • 6
2 Solutions
 
richsarkAuthor Commented:
See code below:

I cant seem to understand why for allow_transfer is only showing 1 IP address on some??

Is it because one that are listed as /16 is screwing up the output?

};

zone "_msdcs.as.foo.edu" in {
      type master;
      file "db._msdcs.as.foo.edu";
      allow-update { 128.163.119.96;128.163.119.95;128.163.119.94;128.163.119.93;128.163.119.103; };
      allow-query { Any; };
      allow-transfer { 128.163/16; };
      notify no;
};

Thanks.
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            print "$zone allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "$zone allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S+)/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    print "$zone allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "$zone allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
wilcoxonCommented:
Generally, it would be something like this to capture the addresses:

$line =~ m{allow-transfer\s*{\s*(\d[\d\.;]+?);\s*};
$xfer_addr = $1;

I'll look at your script when it is posted...
0
 
richsarkAuthor Commented:
Hi wilcoxon,

Script posted.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
wilcoxonCommented:
This should fix it...
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            $allow_update =~ s{;\s*}{, }g;
            print "$zone allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "$zone allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S[\/\w\d\.;\s]+?);\s*}/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    $allow_update =~ s{;\s*}{, }g;
    print "$zone allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "$zone allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
richsarkAuthor Commented:
Yup, That did it

I see you modified line 33, is that right?

if (/^\s*allow-transfer\s*{\s*(\S[\/\w\d\.;\s]+?);\s*}/) {
0
 
wilcoxonCommented:
Yep.  That was the important change.  The only other changes I made was to make output spacing a little nicer (adding lines 13 and 42 - similar to what was already there for $allow_xfer).
0
 
richsarkAuthor Commented:
Oh... Some lines have text in them for allow transfer and allow update, I need that as well.

Then I can bring to xcel and do a find replace on the name and convert to IP's

};

zone "worldof.org" in {
      type master;
      file "db.worldof.org";
      allow-update { None; };
      allow-query { Any; };
      allow-transfer { "blesstransfers"; };
      notify no;
};
0
 
wilcoxonCommented:
just add " inside the char class at line 34.  It already allowed words (but wasn't allowing quotes).

        if (/^\s*allow-transfer\s*{\s*(\S["\/\w\d\.;\s]+?);\s*}/)
0
 
richsarkAuthor Commented:
Ok, I see,

Final code is below if you concur

Thanks !
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            $allow_update =~ s{;\s*}{, }g;
            print "$zone allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "$zone allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S["\/\w\d\.;\s]+?);\s*}/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    $allow_update =~ s{;\s*}{, }g;
    print "$zone allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "$zone allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
wilcoxonCommented:
That looks fine to me.
0
 
richsarkAuthor Commented:
Sorry to be a pain

It should be like so, in addition, I played with the script to look like so...

conf zone modify foo.com set allow_transfer="[168.147.0.0/24,192.168.114.0/24]"

but I am getting

conf zone foo.com modify set allow_transfer="[168.147.0.0/24,192.168.114.0/24]"

Whay am i missing?
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            $allow_update =~ s{;\s*}{, }g;
            print "conf $zone modify set allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "conf $zone modify set allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S["\/\w\d\.;\s]+?);\s*}/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    $allow_update =~ s{;\s*}{, }g;
    print "conf $zone modify set allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "conf $zone modify set allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
richsarkAuthor Commented:
I can open a new thread if I am out of line???
0
 
richsarkAuthor Commented:
Sorry, made a mistake. I did not want to close this. I wanted to award points
0
 
wilcoxonCommented:
If I'm understanding what you're asking, You can simply change your print statements.  This would be for the allow_update (line 14 and 43):

print "conf zone modify $zone set allow_update=\"[$allow_update]\"\n";
0
 
richsarkAuthor Commented:
Thanks for the quick response
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now