include_once "adodb/adodb-exceptions.inc.php"; include_once "adodb/adodb.inc.php"; $DB =& NewADOConnection("postgres://postgres:@localhost/ip_stat?persist"); if (!$DB) { print "Error\n"; exit; } //system( "wget ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest" ); $date = new DateTime("2003-01-01"); $last = new DateTime("2004-01-01"); while ($date < $last) { $file = "ripencc." . $date->format("Ymd"); print $file . "\n"; system("wget ftp://ftp.ripe.net/ripe/stats/old-format/{$file} 2>/dev/null"); print ">> " . date("h:i:s a") . "\n"; parse_delegated($date->format("Y-m-d"), $file, false); print "<< " . date("h:i:s a") . "\n"; unlink("{$file}"); $date->modify("1 week"); } function parse_delegated($on_date, $file, $new_format = true) { global $DB; $file = fopen($file, 'r'); if (!$file) { exit; } while (!feof($file)) { $data = fgetcsv($file, 5000, "|"); //ripencc|NL|ipv4|24.132.0.0|32768|19971013|allocated ^M if ($data[2] != "ipv4" || $data[1] == '*') {
//system( "wget ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest" ); if ($argc < 6) { print "Usage:\n"; print "\t\tphp get-opt.php <URL> <RIR> <FROM_DATE> <TO_DATE> <ZIP> <OLD-FORMAT>\n"; exit(1); } $url = $argv[1]; $RIR = $argv[2]; $date = new DateTime($argv[3]); $last = new DateTime($argv[4]); $bzipped = $argv[5]; $old_format = $argv[6]; while ($date < $last) { $file = get_file($date); print ">> " . date("h:i:s a") . "\n"; parse_delegated($date->format("Y-m-d"), $file, !$old_format); print "<< " . date("h:i:s a") . "\n"; unlink("{$file}"); $date->modify("4 week"); } function get_file($date) { global $bzipped, $url, $RIR, $old_format; if ($old_format == "apnic") { $file = "{$RIR}-" . $date->format("Y-m-d"); } elseif (isset($old_format)) { $file = "{$RIR}." . $date->format("Ymd"); } else { $file = "delegated-{$RIR}-" . $date->format("Ymd"); } print $file . "\n";