Solved

Condition help/modification needed on an exsisting perl script

Posted on 2009-03-31
52
257 Views
Last Modified: 2012-05-06
Hello, I have this script that i obtained here with the help of experts.

Anyway I have a requirement to add and another condidtion like so

Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=CARD
                other=100.100.100.1
        notify=Use Server Value

I need the below script to capture and report on what the ACL Templates= as well as what is under other= value

I am hoping  the report will look like this:

2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to = Use List with the value of =CARD

Then if the other condition for use list

2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to = other with the value of =100.100.100.1

Or prefered,  combine them if all or some are matched

2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to = Use List with the values of Template Name= CARD and other=100.100.100.1

Can you someone modify my script to make this so?

Thanks in advanced



#!/usr/bin/perl -w

use strict;

 

my @revlist = `getrevlist.exe -u xx -p xx -o Orig`;

 

open OUT, ">final-results.txt" or die;

 

foreach(@revlist) {

   if(/,(.*)$/) {

      my $network = $1;

      print "Checking $network\n";

      my $dnsoptions = `getzoneprof.exe -u xx -p xx -a $network -o Orig`;

 

      if($dnsoptions =~ /Sark DNS 4\.X (.*?)allow-update=(.*?)$/ism) {

        # print "$network: allow-update=$2\n";

        my $option = $2;

        if($option =~ /Any|None|User Server Value|Use List|localhost|Use Template|other|localnets/) {

            print "$option matched criteria\n";

#           print "Under Sark DNS 4.X Options field, found allow-update is set to ANY\n";

            print OUT "$network\nUnder Sark DNS 4.X Options field, found allow-update is set to = $option\n\n";

        }

      }

      else {

        # print nothing

      }

   }

} 

 

close OUT

Open in new window

0
Comment
Question by:richsark
  • 35
  • 17
52 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24029995
So the output you posted is what comes from the getzoneprof program?

In your desired output, where does the 2.0.0.0/8 come from?
0
 
LVL 1

Author Comment

by:richsark
ID: 24030067
Hi, the 2.0.0.0/8 gets built from the $network flag that is ran from the the first step.
It looks like this:
2.in-addr.arpa,2.0.0.0/8
4.in-addr.arpa,4.0.0.0/8
5.in-addr.arpa,5.0.0.0/8
Then we parse out the first part, and use the information from the first comma
Yes, it comes from the getzoneprof program. It has many flags in it.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24030275
For the "other" stuff, will it always be "other=...", or could there be anything there?  Do you need to find what is there by how much it is indented?
0
 
LVL 1

Author Comment

by:richsark
ID: 24030676
Hi, for the additions only under:
Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=CARD
                other=100.100.100.1
        notify=Use Server Value
This list is long but I am only interested on what under Sark DNS 4.X Options
allow-update=Use List
                ACL Templates=CARD
                other=100.100.100.1
Yes, it will always be allow-update=, ACL Templates=, and other= headings, but I dont want to loose my origianl condiations
/Any|None|User Server Value|Use List|localhost|Use Template|other|localnets
 
0
 
LVL 1

Author Comment

by:richsark
ID: 24031370
Hi, Adam, Hate to push ya, have you had a min to look at my last post above?
Thanks
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24033069

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;
 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

	next unless /,(.*)$/;

	my $network = $1;

	

	print "Checking $network\n";

	my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

	

	next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=(.*?).*?ACL Template\s*=\s*([^\r\n]*?).*?other=([^\r\n]*)$/ism) {

	my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ($1, $2, $3, $4);

	

	next unless $option =~ /(Any|None|User Server Value|Use List|localhost|Use Template|other|localnets)/;

	print $out "$network\n";

	print $out "Under Sark DNS 4.X Options field found, "

	      .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

	      .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24037920
HI Adam, I am getting some errors

syntax error at E:\rich\cli\Pull-fwd-all.pl line 4, near "open"
Can't use global $! in "my" at E:\rich\cli\Pull-fwd-all.pl line 4, near "Could not open output: $!"
syntax error at E:\qip-62\cli\Pull-fwd-all.pl line 13, near "/Sark DNS 4.X ([^\r\n]*).*?allow-update=(.*?).*?ACL Template\s*=\s*([^\r\n]*?).*?other=([^\r\n]*)
$/ism) "
Can't use global $1 in "my" at E:\rich\cli\Pull-fwd-all.pl line 14, near "($1"
Missing right curly or square bracket at E:\rich\cli\Pull-fwd-all.pl line 23, at end of line
Execution of E:\rich\cli\Pull-fwd-all.pl aborted due to compilation errors.

Also can we make sure I also dont loose these options please:

/Any|None|User Server Value|Use List|localhost|Use Template|other|localnets
0
 
LVL 1

Author Comment

by:richsark
ID: 24039322
HI Adam, I have tried to t/s this, but its beyond my skill set for now. Are you able to take a look at it? I am anxious to try this :)
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24040969

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

        next unless /,(.*)$/;

        my $network = $1;

        

        print "Checking $network\n";

        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

        

        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=(.*?).*?ACL Template\s*=\s*([^\r\n]*?).*?other=([^\r\n]*)$/ism;

        my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ($1, $2, $3, $4);

        

        next unless $Option =~ /(Any|None|User Server Value|Use List|localhost|Use Template|other|localnets)/;

        print $out "$network\n";

        print $out "Under Sark DNS 4.X Options field found, "

              .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

              .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24042923
HI, I ran it, It runs through the checking, but nothing was matched or produced a output file.

The section of the contents I am looking for us labled as:

Sark DNS 4.X Options

The file its checking has a whole bunch of data but I am looking for a particular section where these conditions trigger on.  
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24043383
Try this for line 12.  If that doesn't fix the problem, attach a file with the output from getzoneprof for a few of the networks.


next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*).*?ACL Template\s*=\s*([^\r\n]*?).*?other=([^\r\n]*)$/ism;

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24043837
HI Adam, I added the change above , but still no triggers to output file.

this is the complete file

Checking 76.0.0.0/8

Zone=76.0.0.0/8
ParentAddress=
NetworkAddress=76.0.0.0
dnsServers=IP90S270.svr.sark.net P 0,dns1.svr.sark.net ,ibe1nse09.svr.sark.net S 0,ippam1.sark.net
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@mail.com
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIN-2.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIN-1.X Options
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Sark DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0

0
 
LVL 39

Expert Comment

by:Adam314
ID: 24044113
There is no "ACL Template", and "other".  The script assumed these were always there.  This version will work even if they are missing.

Also, your original pattern for the allow-update had "User Server Value", when it should have been (apparantely) "Use Server Value".  I've made these fixes, and here is an update.
my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

	next unless /,(.*)$/;

	my $network = $1;

	

	print "Checking $network\n";

	my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

	

	next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*).*?(ACL Template\s*=\s*([^\r\n]*?))?.*?(other=([^\r\n]*))?/ism;

	my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ($1, $2, $4, $6);

	

	next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use Template|other|localnets)/;

	

	print $out "$network\n";

	print $out "Under Sark DNS 4.X Options field found, "

	      .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

	      .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24044143
Ok, will try, Yes All these variables may vary depending on the $network. Thats why we are triggering with all variations.

Thanks Adam

0
 
LVL 1

Author Comment

by:richsark
ID: 24045511
HI Adam, Got a minor error:

Use of uninitialized value in concatenation (.) or string at E:\rich\cli\Pull-fwd-all.pl line 19.
0
 
LVL 1

Author Comment

by:richsark
ID: 24048567
Adam, I have tried to diagnose the issue above and seem to make it worse then better.

Can you give it a shot please?

I feel that we are so close to solving this

 
0
 
LVL 1

Author Comment

by:richsark
ID: 24050242
Hi, I think I am not making progress, its breaking more

Help !!



my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

        next unless /,(.*)$/;

        my $network = $1;

        

        print "Checking $network\n";

        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

        

        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*).*?(ACL Template\s*=\s*([^\r\n]*?))?.*?(other=([^\r\n]*))?/ism;

        my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ($1, $2, $4, $6);

        

        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use Template|other|localnets)/;

        

        print $out "$network\n";

        print $out "Under Sark DNS 4.X Options field found, "
 

print  "Under Sark DNS 4.X Options field found,";

        print "$AllowUpdate = $AllowUpdate . allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate";

        print   . "and other=$Other\n";

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24050643
Ok, I think it was my fault, when I got the code, I took out the ./ from ./getrevlist.exe and ran it only with getrevlist.exe

Once I put it back, it ran, but I am still missing Template Varaible and Other

See below from an excerpt of the "final-results.txt"



2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name= and other=

4.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use Server Value with the values Template Name= and other=

5.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use Server Value with the values Template Name= and other=

Also, lets not write values Template Name= and other= if its not found. No need to waste lines.


So for 2.0.0.0/8 network, you can see real output: The format is exaclty like shown with the Tab as a space in ACL Templates and other

Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=CARD
                other=100.100.100.1

So I clearly shows, that there is ACL Templates=CARD and other=100.100.100.1

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

        next unless /,(.*)$/;

        my $network = $1;

        

        print "Checking $network\n";

        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;        

        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*).*?(ACL Templates\s*=\s*([^\r\n]*?))?.*?(other=([^\r\n]*))?/ism;

        my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ($1, $2, $4, $6);

        

        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|ACL Templates|other|localnets)/;

        

        print $out "$network\n";

        print $out "Under Sark DNS 4.X Options field found, "

              .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

              .    "and other=$Other\n\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24052216
Hi, Have a stumped you ?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24052723
Takes some time before I get to look at this.

The warnings will be there when there is no ACL Template or no other.  To solve it, add these after line 12:
	$ACLTemplate='*none*' unless $ACLTemplate;

	$Other='*none*' unless $Other;

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24052771
ok, will do Adam,
 
What about my other question:  I am still missing Template Varaible and Other even though it exisits?

See below from an excerpt of the "final-results.txt"
2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name= and other=

 
0
 
LVL 1

Author Comment

by:richsark
ID: 24053403

I added the new lines, but still no ACL Templates or other being written:

2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=*none and other=*none*


So I clearly shows, that there is ACL Templates=CARD and other=100.100.100.1So for 2.0.0.0/8 network, you can see real output:

The format is exactly like shown with the Tab as a space in ACL Templates and other

Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=CARD
                other=100.100.100.1
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24053653

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

	next unless /,(.*)$/;

	my $network = $1;

	

	print "Checking $network\n";

	my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

	

	next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*)/is;

	print "Found dns options...\n";

	my ($Option, $AllowUpdate) = ($1, $2);

	my $ACLTemplate=$1 if $dnsoptions =~ /^\s*ACL Templates\s*=\s*(.*)$/m;

	my $Other=$1 if $dnsoptions =~ /^\s*other\s*=\s*(.*)$/m;

	$ACLTemplate='*none*' unless $ACLTemplate;

	$Other='*none*' unless $Other;

	

	next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use Template|other|localnets)/;

	

	print $out "$network\n";

	print $out "Under Sark DNS 4.X Options field found, "

	      .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

	      .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24055996
HI Adam, all good except one minor issue:

Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use List
                ACL Templates=CARD;GTILL;NONDNS;CORE;DMZBP;ESF;RST;THRSHOLD;NMGS;ABLE1
                other=
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=


If you notice above, Its picking up ACL Templates under allow-transfer, need to focus only under what under allow-update group


Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=CARD
                other=100.100.100.1
0
 
LVL 1

Author Comment

by:richsark
ID: 24059432
Hi Adam,  sorry to nag you as always, but could you look at my above issue please.

Thanks
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24060862
Is it possible for either "ACL Template=" or "other=" to appear anywhere after the "allow-update" other than in the allow-update section?

Meaning, could you have this, where the ACL Templates and other are after allow-update, but not in the allow-update section:

Sark DNS 4.X Options

       Import External Updates=False

       allow-notify=Use Server Value

       allow-query=Use Server Value

       allow-transfer=Use Server Value

       allow-update=Use List

       something-else=some value

               ACL Templates=CARD

               other=100.100.100.1

Open in new window

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:richsark
ID: 24060894
I only need ACL Templates and other to appear under allow-update, I dont want it anywhere else, like under allow-query, allow-transfer

Thanks
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24060979
I was asking if it is possible for it to appear anywhere else.  
0
 
LVL 1

Author Comment

by:richsark
ID: 24061665
Hi Adam,

It can appear under any one on these under Sark DNS 4.x

Import External Updates=False
allow-notify=Use Server Value
allow-query=Use Server Value
allow-transfer=Use Server Value

But I only care from whats under allow-update

allow-update=Use List
                ACL Templates=CARD
                other=100.100.100.1

Does that answer your question?
0
 
LVL 1

Author Comment

by:richsark
ID: 24062042
Oh,  Allow update is the last row that would contain ACL Templates and other
0
 
LVL 1

Author Comment

by:richsark
ID: 24063009
Hi Adam, hate to push you, but I wanted to see if you had a chance to get me another code.

Thanks !
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24063389

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

        next unless /,(.*)$/;

        my $network = $1;

        

        print "Checking $network\n";

        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

        

        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*)/is;

        my ($Option, $AllowUpdate) = ($1, $2);

        my $ACLTemplate=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?ACL Templates\s*=\s*([^\r\n]*)/sm;

        my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/sm;

        $ACLTemplate='*none*' unless $ACLTemplate;

        $Other='*none*' unless $Other;

        

        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use Template|other|localnets)/;

        

        print $out "$network\n";

        print $out "Under Sark DNS 4.X Options field found, "

              .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

              .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24065403

Hi Adam, I just tried the new code and it still does not show the ACL Template and other.

(output from final-results.txt)
2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=*none* and other=*none*

When I manually run it, it clearly showes it under "Sark DNS 4.x:

Zone=2.0.0.0/8
ParentAddress=
NetworkAddress=2.0.0.0
dnsServers=S230.svr.sark.net P 0,srsdns1.svr.sark.net S 0,txrtp1dns.svr.sark.net S 0,txtp2dns.svr.sark.net S 0,srsdnh2.svr.sark.net S 0,es
ne1.svr.sark.net S 0,azrp1dns.svr.sark.net S 0,artp2dns.svr.sark.net S 0,rtp1dns.svr.sark.net S 0,ohrtp2dns.svr.sark.net S 0,inrtp1dns.svr.
nkone.net S 0,irtp2dns.svr.sark.net S 0,ilrtp2dns.svr.sark.net S 0,ilrtp1dns.svr.sark.net S 0,esfdns2.svr.sark.net S 0,mirtpdns.svr.sark.net
0,mirp2dns.svr.sark.net S 0,witp1dns.svr.sark.net S 0,wirtpdns.svr.sark.net S 0,lartp1dns.svr.sark.net S 0,uxns3.cmg.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@sark.net
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIND-9.X Options
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=DMYBP;JTESF
                other=3.3.3.3
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0
        zone-options=

I did correct a word in the code under next unless from ACL Template to ACL Templates



my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

        next unless /,(.*)$/;

        my $network = $1;

        

        print "Checking $network\n";

        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

        

        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*)/is;

        my ($Option, $AllowUpdate) = ($1, $2);

        my $ACLTemplate=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?ACL Templates\s*=\s*([^\r\n]*)/sm;

        my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/sm;

        $ACLTemplate='*none*' unless $ACLTemplate;

        $Other='*none*' unless $Other;

        

        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use Templates|other|localnets)/;

        

        print $out "$network\n";

        print $out "Under Sark DNS 4.X Options field found, "

              .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

              .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24065413
Opps, sorry

Under "next unless" from Use Template to ACL Templates
0
 
LVL 1

Author Comment

by:richsark
ID: 24069022
Hi Adam,  Any luck finding out why the script cant isolate the ACL Templates and other string?

Do you think because its indented?
0
 
LVL 1

Author Comment

by:richsark
ID: 24072572
HI Adam, I guess your not online on weekends :(
0
 
LVL 1

Author Comment

by:richsark
ID: 24076160
Hi,
Any ideas on this issue?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24077709
When I run it, using the output you posted, it gives me this in the final-results.txt file:

Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=DMYBP;JTESF and other=3.3.3.3


This looks correct.  Maybe there are some additional characters which are not displayed in what you posted.  Try this.

From the command line, run this:
    ./getzoneprof.exe -u xx -p xx -a $network -o Orig > output.txt
Replace the xx with the user name and password as needed, and $network with one of the networks.  Then attach the output.txt file here - don't copy/paste.
0
 
LVL 1

Author Comment

by:richsark
ID: 24077989
Ok, here is the output.

I think the indent maybe the cause?

for-adam.txt
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24078845
The indent should be handled by the ".*?" part of the RE.  Using the for-adam.txt file, I get this output in my final-results.txt:

Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=B1DMZBP and other=3.3.3.3

So it is working for me.  We need to figure out why you are getting different output.  Try this script.  Replace the value for $network (on line 2) with a network name.
Post the output here.
#NOTE: Replace the name with an actual network

my $network = 'some_name_here';

my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

if($dnsoptions =~ /Sark DNS 4.X ([^\r\n]*)(.*?)allow-update=([^\r\n]*)/is) {

	print "Match-A:\n  1='$1'\n  2='$2'\n  3='$3'\n";

}

if($dnsoptions =~ /Sark DNS 4.X(.*?)allow-update/) {

	print "Match-B:\n  1='$1'\n";

	if($dnsoptions =~ /Sark DNS 4.X(.*?)allow-update(.*?)ACL Templates/) {

		print "  Match-C:\n    1='$1'\n    2='$2'\n";

		if($dnsoptions =~ /Sark DNS 4.X(.*?)allow-update(.*?)ACL Templates\s*=\s*([^\r\n]*)/sm) {

			print "    Match-D:\n      1='$1'\n      2='$2'\n      3='$3'\n";

		}

		else {print "    Match-D: NO\n";}

	}

	else {print "  Match-C: NO\n";}

}

else {print "Match-B: NO\n";}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24078878
Hi, here you go

E:\rich\cli>ad2.pl
Match-A:
  1='Options'
  2='
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        '
  3='Use List'
Match-B: NO
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24079252
Change line 7 to this:
    if($dnsoptions =~ /Sark DNS 4.X(.*?)allow-update/s) {
and line 9 to this:
    if($dnsoptions =~ /Sark DNS 4.X(.*?)allow-update(.*?)ACL Templates/s) {

0
 
LVL 1

Author Comment

by:richsark
ID: 24079303
E:\rich\cli>ad2.pl
Match-A:
  1='Options'
  2='
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        '
  3='Use List'
Match-B: NO


What do you think is happening?
0
 
LVL 1

Author Comment

by:richsark
ID: 24080149
Any luck?
0
 
LVL 1

Author Comment

by:richsark
ID: 24081563
I am stumped... I guess since there is no reply, I guess you are too :)

I really need to resolve this .
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24082002
Try this... change line 7 to this:
    if($dnsoptions =~ /Sark DNS 4.X(.*?)allow-update/is) {
and line 9 to this:
    if($dnsoptions =~ /Sark DNS 4.X(.*?)allow-update(.*?)ACL Templates/is) {


If that works, then on line 14 and 15 of the original program, where it ends with:
    /sm;
Change it to end with:
    /ism;

0
 
LVL 1

Author Comment

by:richsark
ID: 24082145
Ok, ran the above and got this

E:\rich2\cli>yes.pl
Match-A:
  1='Options'
  2='
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        '
  3='Use List'
Match-B:
  1=' Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        '
  Match-C:
    1=' Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        '
    2='=Use List
                '
    Match-D: NO
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24082272
On line 11, at the end, change:
    /sm
To
    /ism


0
 
LVL 1

Author Comment

by:richsark
ID: 24082652
Its working now, unless you think otherwise,

 I added ism to these two lines and I got the output I was looking for !


my $ACLTemplate=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?ACL Templates\s*=\s*([^\r\n]*)/ism;
my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/ism;

After all this, it was the words "ism"

So:

10.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=other=199.4.240.200 and other=199.4.240.200



my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

        next unless /,(.*)$/;

        my $network = $1;

        

        print "Checking $network\n";

        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

        

        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*)/is;

        my ($Option, $AllowUpdate) = ($1, $2);

        my $ACLTemplate=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?ACL Templates\s*=\s*([^\r\n]*)/ism;

        my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/ism;

        $ACLTemplate='*none*' unless $ACLTemplate;

        $Other='*none*' unless $Other;

        

        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use Templates|other|localnets)/;

        

        print $out "$network\n";

        print $out "Under Sark DNS 4.X Options field found, "

              .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

              .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 24088502
The "i" part of that means ignore case.  Not sure why it didn't work before on your system, but it did on mine... but as long as it's working now...
0
 
LVL 1

Author Comment

by:richsark
ID: 24097361
Yup, all good now, the final code is below

Thanks Adam !

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;

 

open(my $out, ">final-results.txt") or die "Could not open output: $!\n";

 

foreach(@revlist) {

        next unless /,(.*)$/;

        my $network = $1;

        

        print "Checking $network\n";

        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

        

        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*)/is;

        my ($Option, $AllowUpdate) = ($1, $2);

        my $ACLTemplate=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?ACL Templates\s*=\s*([^\r\n]*)/ism;

        my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/ism;

        $ACLTemplate='*none*' unless $ACLTemplate;

        $Other='*none*' unless $Other;

        

        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use Templates|other|localnets)/;

        

        print $out "$network\n";

        print $out "Under Sark DNS 4.X Options field found, "

              .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "

              .    "and other=$Other\n";

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Closing Comment

by:richsark
ID: 31564849
A Genius as always
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to dynamically set the form action using jQuery.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now