GoldenDictでIP所有者を参照する

IP Tips

GoldenDictを用いて、IPアドレスの所有者を参照しやすくしてみたヨ!!

下記NodeJSソースを常駐させて、一番最後のURIをWeb辞書に登録してNE(´^ω^`)

const express = require('express');
const { exec } = require('child_process');
const app = express();
const port = 3002;

app.get('/lookup', async (req, res) => {
const ip = req.query.ip;
if (!ip) {
res.status(400).send('IPアドレスが指定されていません');
return;
}

try {
// whoisコマンドをPromiseとしてラップし、エラーを無視して空の結果を返す
const execPromise = (command) => new Promise((resolve) => {
exec(command, (error, stdout) => {
if (error) {
resolve(''); // エラーが発生した場合は空の結果を返す
} else {
resolve(stdout);
}
});
});

// 両方のwhoisコマンドを実行して結果を待機
const [result1, result2] = await Promise.all([
execPromise(`whois ${ip} | descr.`),
execPromise(`whois -h whois.nic.ad.jp ${ip} | grep 組織名`)
]);

// 結果をまとめてHTMLとして返す
res.send(`<pre>${result1}</pre><pre>${result2}</pre>`);

} catch (error) {
res.status(500).send(`Unexpected Error: ${error}`);
}
});

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
IP Lookup: http://127.0.0.1:3002/lookup?ip=%GDWORD%

コメント

  1. 10yendama より:

    Whoisのかけすぎに注意ね(‘A`)一時的に弾かれちゃうよ

タイトルとURLをコピーしました