Changeset 336 for trunk


Ignore:
Timestamp:
05/24/12 17:28:33 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint updating export for reverse DNS. See #26.

  • Flesh out substitutions and supported patterns for v4 templates
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r335 r336  
    41854185        # only useful for v4 with standard DNS software, since this expands all
    41864186        # IPs in $zone (or possibly $val?) with autogenerated records
     4187
     4188##work
    41874189use Data::Dumper;
    41884190$zone = NetAddr::IP->new($zone);
     
    41924194    my $iplist = $zone->hostenumref;
    41934195    foreach (@$iplist) {
     4196      my $rec = $host;
     4197      _template4_expand(\$rec, $_->addr);
     4198      print "$_ ptr $rec\n";
    41944199    }
    41954200  } else {
    41964201  }
    41974202}
     4203
     4204sub _template4_expand {
     4205  my $tmpl = shift;
     4206  my $ip = shift;
     4207
     4208  my @ipparts = split /\./, $ip;
     4209  my @iphex;
     4210  my @ippad;
     4211  for (@ipparts) {
     4212    push @iphex, sprintf("%x", $_);
     4213    push @ippad, sprintf("%u.3", $_);
     4214  }
    41984215
    41994216# IP substitutions in template records:
    42004217#major patterns:
    42014218#dashed IP, forward and reverse
    4202 #dotted reversed IP (forward is... dumb)
     4219#dotted IP, forward and reverse (even if forward is... dumb)
     4220# -> %r for reverse, %i for forward, leading - or . to indicate separator, defaults to -
     4221# %r or %-r     => %4d-%3d-%2d-%1d
     4222# %.r           => %4d.%3d.%2d.%1d
     4223# %i or %-i     => %1d-%2d-%3d-%4d
     4224# %.i           => %1d.%2d.%3d.%4d
     4225
     4226  $$tmpl =~ s/\%r/\%4d-\%3d-\%2d-\%1d/g;
     4227  $$tmpl =~ s/\%([-.])r/\%4d$1\%3d$1\%2d$1\%1d/g;
     4228  $$tmpl =~ s/\%i/\%1d-\%2d-\%3d-\%4d/g;
     4229  $$tmpl =~ s/\%([-.])i/\%1d$1\%2d$1\%3d$1\%4d/g;
     4230
    42034231#hex-coded IP
     4232# %h
     4233  $$tmpl =~ s/\%h/$iphex[0]$iphex[1]$iphex[2]$iphex[3]/g;
     4234
    42044235#IP as decimal-coded 32-bit value
    4205 #
     4236# %d
     4237  my $iptmp = $ipparts[0]*256*256*256 + $ipparts[1]*256*256 + $ipparts[2]*256 + $ipparts[3];
     4238  $$tmpl =~ s/\%d/$iptmp/g;
     4239
    42064240#minor patterns (per-octet)
     4241# %[1234][dh0]
    42074242#octet
    42084243#hex-coded octet
    42094244#0-padded octet
    4210 
     4245  $$tmpl =~ s/\%([1234])d/$ipparts[$1-1]/g;
     4246  $$tmpl =~ s/\%([1234])h/$iphex[$1-1]/g;
     4247  $$tmpl =~ s/\%([1234])h/$ippad[$1-1]/g;
     4248
     4249} # _template4_expand()
    42114250
    42124251      } elsif ($type == 65283) { # A+PTR template
Note: See TracChangeset for help on using the changeset viewer.