DenoでDNSの問い合わせができないのでその代替手段
Deno.icon Deno 1.9.1 にはまだ Node.js の dns に相当するパッケージがまだ未実装。 (一応 unstable なAPIに resolveDns があるっぽいが、NSレコードの取得などはできない)
なので、まだDNS問い合わせをするような処理は直接的にはかけないが、FetchAPI があるので Google Public DNS を使ってなんとか回避することができる。
code:ts
for await (const line of readLines(Deno.stdin)) {
if (!line) {
continue
}
const res = await fetch(https://dns.google.com/resolve?name=${line}&type=A)
if (res.ok) {
console.log({ domain: line, response: await res.json() })
}
}
実行するときは、--allow-net をつけることをお忘れなく
code:sh
❯ echo -e "google.com" | deno run --allow-net ./index.ts
{
domain: "google.com",
response: {
Status: 0,
TC: false,
RD: true,
RA: true,
AD: false,
CD: false,
}
}