1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 16:35:40 -04:00

Clean out unroutable addresses

This commit is contained in:
Ryan Voots 2017-05-12 16:55:56 -07:00
parent a356d803be
commit e89c203cdd

View file

@ -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();