Solved

Tweak an existing script

Posted on 2009-04-09
8
282 Views
Last Modified: 2012-05-06
Hello, The below script needs to report on a few different parameters

I dont need these values anymore

Sark DNS 4.X
allow-update=
ACL Templates=

The stuff I need is in the same master file we used in the script

Zone=200.200.200.0/24 ($network)

dnsServers=

I would like dnsServers= to be separated by the P ( Primary)  and S ( Secondary) in a list

so the report could look like

$network=
Primary DNS Server= ILS230.svr.sark.net
Secondary DNS Servers=app32dns2.svr.sark.net
                                          app32dns4.svr.sark



The master file from getzoneprof.exe looks like:

Zone=169.69.250.0/24
ParentAddress=169.69.0.0/16
NetworkAddress=169.69.0.0
dnsServers=ILS230.svr.sark.net P 0,app32dns1.svr.sark.net S 0,app32dns2.svr.sark.net S 0,app32dns4.svr.sark.net S 0,app32dns5.svr.sark.net S 0,app32dns6.
svr.sark.net S 0,app32am1.sark.net P 0,app32am2.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=host@hi@sark.com
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Any
        allow-transfer=Any
        allow-update=Any
        check-names=Warn
        notify=No
        zone block of named.conf=
BIND-9.X Options
        allow-notify=Use Server Value
        allow-query=Any
        allow-transfer=Any
        allow-update=Any
        notify=No
        zone block of named.conf=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Any
        allow-transfer=Any
        allow-update=Any
        check-names=Warn
        notify=No
        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=




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
Comment
Question by:richsark
  • 6
  • 2
8 Comments
 
LVL 1

Author Comment

by:richsark
ID: 24109809
Hi, Any ideas on how to tweak this script?
0
 
LVL 1

Author Comment

by:richsark
ID: 24111463
Here is my attempt, but of course it does not work :(



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 =~ /dnsServers ([^\r\n]*).*?S O =([^\r\n]*)/is;

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

        my $Primary=$1 if $dnsoptions =~ /dnsServers*?P =\s*([^\r\n]*)/ism;

        my $Secondary=$1 if $dnsoptions =~ /dnsServers*?S O*?other\s*=\s*([^\r\n]*)/ism;

                

        next unless $Secondary =~ /(S O)/;

         

        print $out "$network\n";

        print $out "Primary Name Server$Primary=, "

              .    "Secondary DNS Server=$Secondary  "

              .    "and other=$Secondary\n";

} 

 

close($out);

Open in new window

0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24112358
Hi richsark,

I have had an attempt at mocking up something that may help you.  See below.  I made some assumptions that in the list of dbSservers, the trailing P 0 indicated a primary server and S 0 indicated a secondary one.

lwadwell
if ($dnsoptions =~ /dnsServers=(.*?)\n/) {
	my $dnsservers = $1;
	print $dnsservers . "\n";
	my @servers = split(/,/,$dnsservers);
	my @primarydns;
	my @secondarydns;
	foreach my $dns ( @servers ) {
		if ( $dns =~ /^(.*)\s+P\s+\d$/ ) {
			push(@primarydns,$1);
		} elsif ( $dns =~ /^(.*)\s+S\s+\d$/ ) {
			push(@secondarydns,$1);
		}
	}
	print "Primary DNS = @primarydns\n";
	print "Secondary DNS = @secondarydns\n";
}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24112387
Hi,

Your assumption is correct,

I also need to add the Network address in variable $network to the report, can that be added to the print statement?

What about the top part, do I just add it to your script? I need them to work together to get the results

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;
 
open(my $out, ">final-results.txt") or die "Could not open output:

foreach(@revlist) {
        next unless /,(.*)$/;
        my $network = $1;
       
        print "Checking $network\n";
        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 25

Accepted Solution

by:
lwadwell earned 500 total points
ID: 24112611
something like below perhaps ...
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`;

        

    if ($dnsoptions =~ /dnsServers=(.*?)\n/) {

	my $dnsservers = $1;

	print $dnsservers . "\n";

	my @servers = split(/,/,$dnsservers);

	my @primarydns;

	my @secondarydns;

	foreach my $dns ( @servers ) {

            if ( $dns =~ /^(.*)\s+P\s+\d$/ ) {

		push(@primarydns,$1);

	    } elsif ( $dns =~ /^(.*)\s+S\s+\d$/ ) {

		push(@secondarydns,$1);

	    }

	}

	my $Secondary = shift(@secondarydns);

        print $out "$network\n";

        print $out "Primary Name Server=@primarydns "

              .    "Secondary DNS Server=$Secondary  "

              .    "and other=@secondarydns\n";

}

} 

 

close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24116199
HI,

I ran the script, the final-results.txt has weird characters

20008
rmr aeS
0
 
LVL 1

Author Closing Comment

by:richsark
ID: 31568499
Thanks ! good work
0
 
LVL 1

Author Comment

by:richsark
ID: 24117618
Disregard my last comment, It was my fault. The script worked perfectly.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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

14 Experts available now in Live!

Get 1:1 Help Now