#! /usr/bin/perl ### DOCUMENTATION AND LICENSE START # input is a SIMS-style blacklist, output is a BIND zonefile. # (c) 2003,2004 William K. Cole. # This documentation and license apply to bltozone.pl version 0.9.2 # # Solid Clues Consulting sample code license # This software is not suitable for use anywhere other than # internally at Solid Clues Consulting. Access to this source # code is provided without any representation or warranty of # suitability for any specific purpose. # THIS SOFTWARE IS NOT LICENSED FOR USE AS-IS!!! # Any use except by the author MUST involve changes to the # software. Software thus derived from this software may be # used without restriction by the person or business creating # the derived software. Such derived software may be redistributed # under the following conditions: # # 1. All derivative source code and any documentation describing # the function of derivative software must reproduce this # "DOCUMENTATION AND LICENSE" block in full and unmodified. # # 2. No fees of any sort may be charged for distribution or # licensing of derivative works. No conditions involving # payment for other goods may be applied to restrict # distribution of derivative works. # # 3. Any distribution of derivative works must include # full source code of the entire derivative work. # # # This license SHOULD NOT be construed as intending to make the # licensed work "Open Source" or "Free" software as those terms # are commonly used or under the definitions of the OSI or FSF. # # Alternative license terms may (or may not) be available from # Solid Clues Consulting. # ### DOCUMENTATION AND LICENSE END use POSIX; use Net::CIDR::Lite; use Net::CIDR; $version=0.9.2; $zone='blackholes.scconsult.com.'; $rp='bill.scconsult.com.'; @ns=('toaster.scconsult.com.', 'fireproof.scconsult.com.'); # don't expect the SN to change more than hourly. # $tstamp=`date +%Y%m%d%H`; # chomp $tstamp; # epoch-based timestamps have more granularity than 'standard' # datestamp zones. $tstamp = time; print "\$TTL 600 ;\n"; print "\$ORIGIN $zone ;\n"; print "\@ 1D IN SOA $ns[0] $rp (\n"; print " $tstamp ; serial\n"; print " 1H ; refresh\n"; print " 15M ; retry\n"; print " 1W ; expiry\n"; print " 600 ) ; minimum\n"; foreach $NS (@ns) { print "\@ 1D IN NS $NS\n"; } $list=Net::CIDR::Lite->new ; open (RANGES,"> /tmp/bltranges"); open (COMMS,"> /tmp/bltcomms"); IN: while (<>) { ($addr, $comment) = split (/;/,$_,2); chomp $comment; $comment =' '.$comment; $comment=~s/;/ /g; ($firstaddr,$junk) = split (/-/, $addr,2); $firstaddr=~s/ //g; $comments{$firstaddr}=$comment; print COMMS "$firstaddr $comment\n"; $addr=~s/[^-0-9\.]//g; next if ( ! $addr=~ m/./) ; print RANGES "$addr"; $list->add_any($addr); print RANGES "added\n"; } $list->clean(); @olist=Net::CIDR::cidr2octets ($list->list); open (OCTETS, "> /tmp/bltoctets"); print OCTETS "@olist\n" ; open (OUTFIRSTS, "> /tmp/bltoutfirst"); OUT: foreach $addr (@olist) { $firstaddr=$addr; while ( $firstaddr !~ m/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ ) { $firstaddr=$firstaddr . ".0"; } print OUTFIRSTS "$firstaddr\n"; @octets = split (/\./,$addr,4); $oline='$ORIGIN '; $oname="$zone"; foreach $octet (@octets) { $oname = "$octet.$oname"; } if ( $comments{$firstaddr} ) { $comm=$comments{$firstaddr}; } print "$oline $oname ; $comm\n"; if ($octets[3]) { $name='@'; } else { $name='*'; } print "$name IN A 127.0.0.2\n"; if ( $comm=~m/[a-zA-Z]/) { print "$name IN TXT \"$comm\"\n"; } }