"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "mkdnstab-0.6b/mkdnstab-0.5b" of archive mkdnstab-0.6b.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 #!/usr/bin/perl
    2 # mkdnstab v 0.5b (C) Miles Lott 10/10/1999 - milos@insync.net
    3 # Make a DNS table for class C or a subset thereof
    4 # as well as creating the conf file for bind8
    5 # I know its not perfect, but it will save you the hassle of typing
    6 # a bunch of addresses manually.
    7 #
    8 # Original release version 09/09/1998 v 0.2
    9 # Added ability to handle up to 3 MX entries 05/26/1999 v 0.3
   10 # Fixed serious reverse table generation bug 07/19/1999 v 0.4
   11 # Add ability to build simple bind8 config
   12 #
   13 # Mods to table output to help reverse problems 10/03/1999 v 0.5a
   14 # Mods to table output to add origin and ttl fields 10/10/1999 v 0.5b
   15 # Cleanup of reverse domain string construction
   16 #
   17 # --------------------------------------------------------------
   18 # create forward, reverse, or simple table?
   19 # comment out $rev and $headers or $fwd and $headers for a
   20 # simple dns style ip table for cutting and pasting.
   21 $fwd=1;
   22 $rev=1;
   23 $headers=1;
   24 
   25 # create the named.conf file as well?
   26 $conf=1;
   27 $dnsconf="named.conf";
   28 
   29 # NEW - Is this a master or slave config?  If it is your ONLY
   30 # nameserver, then it certainly is master.  If not, then set
   31 # $mserver to the ip of the master server.
   32 $ismaster=1;
   33 #$mserver="192.168.100.2";
   34 
   35 # zone file for localhost domain - see the DNS-HOWTO for why
   36 # this is needed
   37 $dnsloc="named.local";
   38 
   39 # forwarders for the named.conf file - for looking up info
   40 # from all other domains, making your dns single-source for a LAN
   41 $forwarder1="198.6.1.1";
   42 # $forwarder2="0.0.0.0";
   43 
   44 # Set to your domain for creation of reverse tables
   45 $domain="domain.net";
   46 
   47 # Set to your subnet address
   48 $subnet="192.168.200";
   49 
   50 # the current machine's hostname and ip address suffix,
   51 # or that of the nameserver (maybe the same?)
   52 $hostname="ns";
   53 $hostip="10";
   54 
   55 # The mailserver(s) for the domain (define up to 3)
   56 # Leave these commented out if not needed! Do not simply
   57 # make them equal to "".
   58 $mailex="mail";
   59 $mailip="20";
   60 $mailpref="100";
   61 
   62 $mailex2="mail2";
   63 $mailip2="21";
   64 $mailpref2="200";
   65 
   66 # $mailex3="mail3";
   67 # $mailip3="22";
   68 # $mailpref3="200";
   69 
   70 # domain master for mail address in dns tables
   71 # example: $master="dnsadmin";
   72 $master="dns";
   73 
   74 # serial number for the zone (typically the date)
   75 # and refresh, retry, expire, and minimum timings
   76 # the defaults here should work
   77 $serial=(time);
   78 $refresh="28800";
   79 $retry="14400";
   80 $expire="360000";
   81 $minimum="10800";
   82 
   83 # Pick a prefix for the manufactured names
   84 # i.e. user01.domain.net
   85 $prefix="user";
   86 
   87 # set to the range or ranges of yer choice
   88 # This enables exclusion of certain ip addresses.  Note that below
   89 # we handle exclusion of the nameserver and mailserver ip, so a full
   90 # range is ok if you want.
   91 #  examples: @foo=(1..50,100..254);
   92 #	     @foo=(1..10,101,102);
   93 @foo=(1..254);
   94 @bar=@foo;
   95 
   96 # Output filenames
   97 $dnsfwd="named.fwd";
   98 $dnsrev="named.rev";
   99 
  100 ############################################
  101 #                                          #
  102 #   No editing below should be necessary   #
  103 #                                          #
  104 ############################################
  105 
  106 print"$0 is making $dnsfwd, $dnsrev and $dnsloc as per the configuration\n";
  107 # --------------------------------------------------------------
  108 #  Now do something, make the dns tables per above instructions
  109 # --------------------------------------------------------------
  110 
  111 if ($fwd = 1) {
  112 open (FWD,">$dnsfwd");
  113 if ($headers = 1) {
  114     print FWD "\$ORIGIN $domain\.\n";
  115     print FWD "\$TTL $minimum\n\n";
  116     print FWD "\@\tIN\tSOA\t$hostname\. $master\.$hostname\.$domain\.\t(\n";
  117     print FWD "\t\t\t\t$serial \;\tSerial\n\t\t\t\t$refresh\t\;\tRefresh\n";
  118     print FWD "\t\t\t\t$retry\t\;\tRetry\n\t\t\t\t$expire\t\;\tExpire\n";
  119     print FWD "\t\t\t\t$minimum\ )\t\;\tMinimum\n\n";
  120     print FWD "\@\t\tIN\tA\t$subnet\.$hostip\n";
  121     print FWD "\@\t\tIN\tNS\t$hostname\n";
  122     print FWD "\@\t\tIN\tMX\t$mailpref\t$mailex\n" if defined $mailex;
  123     print FWD "\@\t\tIN\tMX\t$mailpref2\t$mailex2\n" if defined $mailex2;
  124     print FWD "\@\t\tIN\tMX\t$mailpref3\t$mailex3\n" if defined $mailex3;
  125     print FWD "\n";
  126 }
  127 while (<@foo>) {
  128     if (/\b$hostip\b/) {
  129 	print FWD "$hostname\t\tIN\tA\t$subnet.$hostip\n";next }
  130     if (defined $mailip) { if (/\b$mailip\b/) {
  131 	print FWD "$mailex\t\tIN\tA\t$subnet.$mailip\n";next }}
  132     if (defined $mailip2) { if (/\b$mailip2\b/) {
  133 	print FWD "$mailex2\t\tIN\tA\t$subnet.$mailip2\n";next }}
  134     if (defined $mailip3) { if (/\b$mailip3\b/) {
  135 	print FWD "$mailex3\t\tIN\tA\t$subnet.$mailip3\n";next }}
  136     if (/[0-9][0-9][0-9]/) {
  137 	print FWD "$prefix$_\t\tIN\tA\t$subnet.$_\n";next }
  138     if (/[0-9][0-9]/) {
  139 	print FWD "$prefix$_\t\tIN\tA\t$subnet.$_\n";next }
  140     if (/[0-9]/) {
  141         print FWD "$prefix\60$_\t\tIN\tA\t$subnet.$_\n";next }
  142     shift;
  143 }
  144 close FWD;
  145 }
  146 
  147 # now the reverse table
  148 if ($rev = 1) {
  149    $_=$subnet; while ( /(\d+)\.(\d+)\.(\d+)/g ) {
  150 	$revdom="$3.$2.$1.in-addr.arpa"; }
  151 
  152 open (REV,">$dnsrev");
  153 
  154 if ($headers = 1) {
  155     print REV "\$ORIGIN $revdom\.\n";
  156     print REV "\$TTL $minimum\n\n";
  157     print REV "\@\tIN\tSOA\t$hostname\. $master\.$hostname\.$domain\.\t(\n";
  158     print REV "\t\t\t\t$serial \;\tSerial\n\t\t\t\t$refresh\t\;\tRefresh\n";
  159     print REV "\t\t\t\t$retry\t\;\tRetry\n\t\t\t\t$expire\t\;\tExpire\n";
  160     print REV "\t\t\t\t$minimum\ )\t\;\tMinimum\n\n";
  161     print REV "\@\t\tIN\tPTR\t$domain\.\n";
  162     print REV "\@\t\tIN\tNS\t$hostname\.\n";
  163 }
  164 
  165 while (<@bar>) {
  166     if (/\b$hostip\b/) {
  167 	print REV "$hostip\t\tIN\tPTR\t$hostname\.$domain\.\n";next }
  168     if (defined $mailip) { if (/\b$mailip\b/) {
  169 	print REV "$mailip\t\tIN\tPTR\t$mailex\.$domain\.\n";next }}
  170     if (defined $mailip2) { if (/\b$mailip2\b/) {
  171 	print REV "$mailip2\t\tIN\tPTR\t$mailex2\.$domain\.\n";next }}
  172     if (defined $mailip3) { if (/\b$mailip3\b/) {
  173 	print REV "$mailip3\t\tIN\tPTR\t$mailex3\.$domain\.\n";next }}
  174     if (/[0-9][0-9][0-9]/) {
  175 	print REV "$_\t\tIN\tPTR\t$prefix$_\.$domain\.\n";next }
  176     if (/[0-9][0-9]/) {
  177 	print REV "$_\t\tIN\tPTR\t$prefix$_\.$domain\.\n";next }
  178     if (/[0-9]/) {
  179 	print REV "$_\t\tIN\tPTR\t$prefix\60$_\.$domain\.\n";next }
  180     shift;
  181 }
  182 close REV;
  183 }
  184 
  185 # now the named.conf and local domain files
  186 
  187 if ($conf = 1) {
  188     if ($ismaster) {$domtype="master";} else {$domtype="slave";}
  189     open (CONF,">$dnsconf");
  190     $timeinfo=scalar(localtime(time));
  191     print CONF "\/\/ generated by $0 $timeinfo\n";
  192     print CONF "options \{\n\tlisten-on \{ $subnet.$hostip\; 127.0.0.1\; \}\;\n";
  193     print CONF "\t\/\/ location of the zone files\n\tdirectory \"\/var\/named\"\;\n";
  194     print CONF "\tforwarders \{";
  195     if ($forwarder1) { print CONF "\n\t\t$forwarder1\;"; }
  196     if ($forwarder2) { print CONF "\n\t\t$forwarder2\;"; }
  197     print CONF "\n\t\}\;\n";
  198     print CONF "\t\/\/ make bind8 query on port 53\n\t\/\/ \(may need only if firewalling prohibits other ports\)\n\t";
  199     print CONF "query-source address \* port 53\;\n\}\;\n\n";
  200     print CONF "\/\/\n\/\/ a caching only nameserver config\n\/\/\n";
  201     print CONF "zone \".\" \{\n\ttype hint\;\n\tfile \"named.ca\"\;\n\}\;\n\n";
  202     print CONF "\/\/\n\/\/ configured zones\n\/\/\n";
  203     print CONF "zone \"$domain\" \{\n\ttype $domtype\;\n\tfile \"$dnsfwd\"\;\n";
  204     if (!$ismaster) { print CONF "\tmasters \{\n\t\t$mserver\;\n\t\}\;\n"; }
  205     print CONF "\}\;\n\n";
  206     print CONF "zone \"$revdom\" \{\n\ttype $domtype\;\n\tfile \"$dnsrev\"\;\n";
  207     if (!$ismaster) { print CONF "\tmasters \{\n\t\t$mserver\;\n\t\}\;\n"; }
  208     print CONF "\}\;\n\n";
  209     print CONF "zone \"0.0.127.in-addr.arpa\" \{\n\ttype master\;\n\tfile \"$dnsloc\"\;\n\}\;";
  210     close CONF;
  211 
  212     open (LOC,">$dnsloc");
  213     print LOC "\$TTL 86400\n\n";
  214     print LOC "\@\tIN\tSOA\tlocalhost\. $master\.localhost\.\t(\n";
  215     print LOC "\t\t\t\t$serial \;\tSerial\n\t\t\t\t$refresh\t\;\tRefresh\n";
  216     print LOC "\t\t\t\t$retry\t\;\tRetry\n\t\t\t\t$expire\t\;\tExpire\n";
  217     print LOC "\t\t\t\t86400\ )\t\;\tMinimum\n\n";
  218     print LOC "\t\tIN\tNS\tlocalhost\.\n";
  219     print LOC "1\t\tIN\tPTR\tlocalhost\.\n";
  220     close LOC;
  221 }
  222 
  223 print"\nDone! Now edit the files \"$dnsfwd\" and \"$dnsrev\" to customize to your needs.\n";
  224 print"Verify then copy \"named.conf\" to \/etc.\n";
  225 print"Then move the zone files to the appropriate location, typically \"/var/named\".\n";
  226 print"Also copy \"named.ca\" and \"$dnsloc\" to the same location.\n";
  227 print"Finally, start\/restart the nameserver process.\n";