- Timestamp:
- 05/24/12 17:28:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r335 r336 4185 4185 # only useful for v4 with standard DNS software, since this expands all 4186 4186 # IPs in $zone (or possibly $val?) with autogenerated records 4187 4188 ##work 4187 4189 use Data::Dumper; 4188 4190 $zone = NetAddr::IP->new($zone); … … 4192 4194 my $iplist = $zone->hostenumref; 4193 4195 foreach (@$iplist) { 4196 my $rec = $host; 4197 _template4_expand(\$rec, $_->addr); 4198 print "$_ ptr $rec\n"; 4194 4199 } 4195 4200 } else { 4196 4201 } 4197 4202 } 4203 4204 sub _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 } 4198 4215 4199 4216 # IP substitutions in template records: 4200 4217 #major patterns: 4201 4218 #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 4203 4231 #hex-coded IP 4232 # %h 4233 $$tmpl =~ s/\%h/$iphex[0]$iphex[1]$iphex[2]$iphex[3]/g; 4234 4204 4235 #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 4206 4240 #minor patterns (per-octet) 4241 # %[1234][dh0] 4207 4242 #octet 4208 4243 #hex-coded octet 4209 4244 #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() 4211 4250 4212 4251 } elsif ($type == 65283) { # A+PTR template
Note:
See TracChangeset
for help on using the changeset viewer.