Browse Source

feat: output as sqlite3 database

master
Dnomd343 3 years ago
parent
commit
65457a6f31
  1. BIN
      release/iana-data.db
  2. 73
      src/main.php

BIN
release/iana-data.db

Binary file not shown.

73
src/main.php

@ -15,33 +15,6 @@ writeFile($release_path . 'tld-list.txt', implode(PHP_EOL, $tlds) . PHP_EOL);
// Analyse all TLDs from html files
$data = getTldsInfo($tlds, $html_path . 'tlds/');
// $str = $data['.to']['admin_contact']['org'];
// echo preg_replace('/[\s]+/', ' ', $str);
// echo $str;
// exit;
// var_dump($data['.com']);
// exit;
foreach ($data as $index => $row) {
// if ($row['admin_contact']['voice'] === false) {
// echo $index . ' -> ' . implode(' | ', $row['manager']['addr']) . PHP_EOL;
// if (count($row['nameserver']) === 0) { continue; }
// echo $row['website'] . PHP_EOL;
// echo $row['whois'] . PHP_EOL;
// echo $row['last_updated'] . PHP_EOL;
// echo $row['regist_date'] . PHP_EOL;
// echo $index . ' -> ' . $row['tech_contact']['name'] . PHP_EOL;
// echo $index . ' -> ' . $row['tech_contact']['org'] . PHP_EOL;
// echo $index . ' -> ' . implode(' | ', $row['tech_contact']['addr']) . PHP_EOL;
// echo $index . ' -> ' . $row['tech_contact']['email'] . PHP_EOL;
// echo $index . ' -> ' . $row['tech_contact']['voice'] . PHP_EOL;
// echo $index . ' -> ' . $row['tech_contact']['fax'] . PHP_EOL;
// }
}
// return;
// Output data by json format
writeFile($release_path . 'all-data.json', json_encode($data));
@ -52,7 +25,42 @@ foreach ($data as $index => $row) {
$whoisStr .= $index . ',' . $row['whois'] . PHP_EOL;
}
}
writeFile('../release/whois-server.csv', $whoisStr);
writeFile($release_path . 'whois-server.csv', $whoisStr);
// Output into sqlite3 database
$init_sql =<<<EOF
CREATE TABLE data (
tld TEXT NOT NULL,
type TEXT NOT NULL,
manager TEXT NOT NULL,
admin_contact TEXT NOT NULL,
tech_contact TEXT NOT NULL,
nameserver TEXT NOT NULL,
website TEXT NOT NULL,
whois TEXT NOT NULL,
last_updated TEXT NOT NULL,
regist_date TEXT NOT NULL
);
EOF;
$db = new tldDB($release_path . 'iana-data.db');
$db->exec($init_sql);
$insert_sql = 'INSERT INTO data ';
$insert_sql .= '(tld,type,manager,admin_contact,tech_contact,nameserver,website,whois,last_updated,regist_date) ';
$insert_sql .= 'VALUES (';
foreach ($data as $tld => $info) {
$sql = $insert_sql . '\'' . $tld . '\',';
foreach ($info as $index => $field) {
if ($index === 'manager' || $index === 'admin_contact' || $index === 'tech_contact' || $index === 'nameserver') {
$field = base64_encode(json_encode($field));
}
$sql .= '\'' . $field . '\'';
if ($index !== 'regist_date') {
$sql .= ',';
}
}
$db->exec($sql . ');');
}
function writeFile($filename, $data) {
$file = fopen($filename, 'w');
@ -60,4 +68,13 @@ function writeFile($filename, $data) {
fclose($file);
}
class tldDB extends SQLite3 {
public function __construct($filename) {
$this->open($filename);
}
public function __destruct() {
$this->close();
}
}
?>

Loading…
Cancel
Save