mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 15:55:42 -04:00
Add some ASN db creation scripts
This commit is contained in:
parent
720843cb54
commit
a356d803be
2 changed files with 40 additions and 0 deletions
1
asndb/README.md
Normal file
1
asndb/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ASN db comes from https://iptoasn.com/
|
39
asndb/mkasn.pl
Executable file
39
asndb/mkasn.pl
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use autodie;
|
||||||
|
use DBI;
|
||||||
|
|
||||||
|
sub fmtip($) {
|
||||||
|
my $ip = shift;
|
||||||
|
sprintf "%03d.%03d.%03d.%03d", split(/\./, $ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
open(my $tsv, "<", "ip2asn-v4.tsv");
|
||||||
|
|
||||||
|
my $dbh = DBI->connect("dbi:SQLite:dbname=asn.db", "", "", {RaiseError => 1});
|
||||||
|
|
||||||
|
$dbh->do("DROP TABLE IF EXISTS asn;");
|
||||||
|
$dbh->do(q{CREATE TABLE asn (
|
||||||
|
start varchar(15) NOT NULL,
|
||||||
|
end varchar(15) NOT NULL,
|
||||||
|
asn INTEGER NOT NULL,
|
||||||
|
country TEXT,
|
||||||
|
desc TEXT
|
||||||
|
);
|
||||||
|
CREATE INDEX asn_start ON asn (start);
|
||||||
|
CREATE INDEX asn_end ON asn (end);
|
||||||
|
CREATE INDEX ON asn_asn ON asn (asn);});
|
||||||
|
|
||||||
|
$dbh->begin_work;
|
||||||
|
my $insert_sth = $dbh->prepare("INSERT INTO asn (start, end, asn, country, desc) VALUES (?, ?, ?, ?, ?);");
|
||||||
|
|
||||||
|
while (my $line = <$tsv>) {
|
||||||
|
chomp $line;
|
||||||
|
my ($start, $end, $asn, $country, $desc) = split /\t/, $line;
|
||||||
|
|
||||||
|
printf "%s - %s\n", fmtip($start), fmtip($end);
|
||||||
|
$insert_sth->execute(fmtip $start, fmtip $end, $asn, $country, $desc);
|
||||||
|
}
|
||||||
|
$dbh->commit();
|
Loading…
Add table
Reference in a new issue