Advertisement
rg443

geoip2 lite asn mysql import

Jan 7th, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.26 KB | None | 0 0
  1. /*
  2. curl -O http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN-CSV.zip
  3. unzip -j GeoLite2-ASN-CSV.zip
  4.  
  5. */
  6.  
  7. drop table if exists geoip2asn;
  8. CREATE TABLE geoip2asn (
  9.     i1 INT(10) UNSIGNED NULL DEFAULT inet_aton(substring_index(prefix,'/',1)) primary key,
  10.     i2 INT(10) UNSIGNED NULL DEFAULT (inet_aton(substring_index(prefix,'/',1))+power(2,32-substring_index(prefix,'/',-1))-1),
  11.     prefix VARCHAR(18) NULL DEFAULT NULL,
  12.     asn INT(10) UNSIGNED NULL DEFAULT NULL,
  13.     asname VARCHAR(100) NULL DEFAULT NULL,
  14.     index asn(asn)
  15. )
  16. ENGINE=MyISAM;
  17.  
  18.  
  19.  
  20. truncate table geoipasn;
  21. load data infile '/tmp/GeoLite2-ASN-Blocks-IPv4.csv' into table geoip2asn
  22. FIELDS TERMINATED BY ','
  23. OPTIONALLY ENCLOSED BY '"'
  24. LINES TERMINATED BY '\n'
  25. IGNORE 1 lines
  26. (prefix,asn,asname);
  27. optimize table geoipasn;
  28.  
  29. /*
  30. select asn,sum(1)n,sum(i2-i1)+2 ips,concat("AS",asn," - ",asname)asdescr from geoip2asn group by asn with rollup;
  31. select i1,i2,prefix,asn,asname,convert(substring_index(prefix,'/',-1),int) as pl,i2-i1+1 ips from geoip2asn where asn=3356 order by i1,i2 desc;
  32.  
  33. -- select * from geoip2asn where inet_aton('195.177.230.0') between i1 and i2;
  34. -- set @i:=inet_aton('8.8.8.8');select * from (select * from geoip2asn where @i>=i1 order by i1  desc limit 1) A where i2>=@i;
  35.  
  36. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement