GeoIPCountry.csv'); shell_exec('cut -d , -f 3-5 GeoIPv6.csv | tr -d " " >> GeoIPCountry.csv'); if (($fd = fopen('GeoIPCountry.csv', 'r')) !== false) { $DB->query("TRUNCATE TABLE geoip_country"); $Values = array(); $Count = 0; while (($Data = fgetcsv($fd)) !== false) { list($StartIP, $EndIP, $CountryID) = $Data; $Values[] = "($StartIP, $EndIP, '$CountryID')"; $Count++; if ($Count % $LIMIT == 0) { $DB->query(" INSERT INTO geoip_country (StartIP, EndIP, Code) VALUES ".implode(', ', $Values)); $Values = array(); } } if (count($Values) > 0) { $DB->query(" INSERT INTO geoip_country (StartIP, EndIP, Code) VALUES ".implode(', ', $Values)); } echo 'GeoIP_Country: There are '.($Count+count($Values)).' entries
'; } else { echo 'Country Error'; } shell_exec('rm GeoIPCountryCSV.zip GeoIPv6.csv.gz GeoIPCountryWhois.csv GeoIPv6.csv GeoIPCountry.csv'); // ASN (v4) section shell_exec('wget http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2.zip'); shell_exec('unzip GeoIPASNum2.zip'); if (($fd = fopen('GeoIPASNum2.csv', 'r')) !== false) { $DB->query("TRUNCATE TABLE geoip_asn"); $Values = array(); $Count = 0; while (($Data = fgetcsv($fd)) !== false) { list($StartIP, $EndIP, $ASN) = $Data; $ASN = substr($ASN, 2, strpos($ASN, ' ') ? strpos($ASN, ' ')-2 : strlen($ASN)-2); $Values[] = "(INET6_ATON(INET_NTOA($StartIP)), INET6_ATON(INET_NTOA($EndIP)), $ASN)"; $Count++; if ($Count % $LIMIT == 0) { $DB->query(" INSERT INTO geoip_asn (StartIP, EndIP, ASN) VALUES ".implode(', ', $Values)); $Values = array(); } } if (count($Values) > 0) { $DB->query(" INSERT INTO geoip_asn (StartIP, EndIP, ASN) VALUES ".implode(', ', $Values)); } echo 'GeoIP_ASN (v4): There are '.($Count+count($Values)).' entries
'; } else { echo 'ASNv4 Error'; } shell_exec('rm GeoIPASNum2.zip GeoIPASNum2.csv'); // ASN (v6) section shell_exec('wget http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2v6.zip'); shell_exec('unzip GeoIPASNum2v6.zip'); if (($fd = fopen('GeoIPASNum2v6.csv', 'r')) !== false) { $Values = array(); $Count = 0; while (($Data = fgetcsv($fd)) !== false) { list($ASN, $StartIP, $EndIP) = $Data; $ASN = substr($ASN, 2, strpos($ASN, ' ') ? strpos($ASN, ' ')-2 : strlen($ASN)-2); $Values[] = "(INET6_ATON('$StartIP'), INET6_ATON('$EndIP'), $ASN)"; $Count++; if ($Count % $LIMIT == 0) { $DB->query(" INSERT INTO geoip_asn (StartIP, EndIP, ASN) VALUES ".implode(', ', $Values)); $Values = array(); } } if (count($Values) > 0) { $DB->query(" INSERT INTO geoip_asn (StartIP, EndIP, ASN) VALUES ".implode(', ', $Values)); } echo 'GeoIP_ASN (v6): There are '.($Count+count($Values)).' entries
'; } else { echo 'ASNv6 Error'; } shell_exec('rm GeoIPASNum2v6.zip GeoIPASNum2v6.tmp GeoIPASNum2v6.csv'); View::show_footer();