#! /usr/bin/perl -w use strict; use FindBin; use IO::File; use JSON; use Net::Patricia; if (1 > @ARGV) { die <<_EOF_ usage: ${FindBin::Script} file_aggregate_counts.shar [...] _EOF_ } my $filterPt = new Net::Patricia(AF_INET6) or die; $filterPt->add_string("2002::/16") or die; # 6to4 my $HR = {}; # hashref for hash to be emitted as JSON foreach my $prefix_counts_file (@ARGV) { if ($prefix_counts_file =~ m/aggregate_counts.shar/) { my $fh = IO::File->new($prefix_counts_file, "r") or die; my $prefix; while (<$fh>) { chomp; if (m/([^_]+--_\d+)_aggregate_counts/) { $prefix = $1; $prefix =~ s/-/:/g; $prefix =~ s|_|/|g; if ($filterPt->match_exact_string($prefix)) { undef $prefix; next; } } elsif (m/^_EOF_/) { undef $prefix; } elsif (defined($prefix)) { my @F = split(m/\s+/); die unless 2 == @F; if (64 == $F[0]) { $HR->{$prefix}->{'64_count'} += $F[1]; } elsif (128 == $F[0]) { $HR->{$prefix}->{'addr_count'} += $F[1]; } } } undef $fh; } else { warn "$prefix_counts_file: confusing."; } } if (1) { print JSON->new->pretty->encode($HR); } else { print JSON->new->encode($HR); } exit;