From e89c203cdd68f6c318d78a0720a5b0aecd6d5826 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Fri, 12 May 2017 16:55:56 -0700 Subject: [PATCH] Clean out unroutable addresses --- asndb/mkasn.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/asndb/mkasn.pl b/asndb/mkasn.pl index 5dd2cd7..4da440f 100755 --- a/asndb/mkasn.pl +++ b/asndb/mkasn.pl @@ -12,7 +12,7 @@ sub fmtip($) { open(my $tsv, "<", "ip2asn-v4.tsv"); -my $dbh = DBI->connect("dbi:SQLite:dbname=asn.db", "", "", {RaiseError => 1}); +my $dbh = DBI->connect("dbi:SQLite:dbname=../var/asn.db", "", "", {RaiseError => 1}); $dbh->do("DROP TABLE IF EXISTS asn;"); $dbh->do(q{CREATE TABLE asn ( @@ -32,8 +32,16 @@ my $insert_sth = $dbh->prepare("INSERT INTO asn (start, end, asn, country, desc) while (my $line = <$tsv>) { chomp $line; my ($start, $end, $asn, $country, $desc) = split /\t/, $line; - + next if $asn eq 0; printf "%s - %s\n", fmtip($start), fmtip($end); $insert_sth->execute(fmtip $start, fmtip $end, $asn, $country, $desc); } +#$dbh->commit(); +#$dbh->begin_work(); +for my $ip (0..255) { + my $rv = $dbh->do("DELETE FROM asn WHERE start <= ? AND end >= ?", {}, fmtip "10.$ip.0.0", fmtip "10.$ip.0.0"); + $rv+=$dbh->do("DELETE FROM asn WHERE start <= ? AND end >= ?", {}, fmtip "172.$ip.0.0", fmtip "172.$ip.0.0") if $ip >= 16 || $ip <= 32; + $rv+=$dbh->do("DELETE FROM asn WHERE start <= ? AND end >= ?", {}, fmtip "192.168.$ip.0", fmtip "192.168.$ip.0"); + print "Removed $rv for $ip\n"; +} $dbh->commit();