2023-06-22 16:24:36 +02:00
|
|
|
const dns = require('dns');
|
|
|
|
const util = require('util');
|
2023-08-09 23:33:36 +02:00
|
|
|
const middleware = require('./_common/middleware');
|
2023-06-22 16:24:36 +02:00
|
|
|
|
2023-08-09 23:33:36 +02:00
|
|
|
const handler = async (url) => {
|
|
|
|
let hostname = url;
|
2023-06-22 16:24:36 +02:00
|
|
|
|
|
|
|
// Handle URLs by extracting hostname
|
|
|
|
if (hostname.startsWith('http://') || hostname.startsWith('https://')) {
|
|
|
|
hostname = new URL(hostname).hostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const lookupPromise = util.promisify(dns.lookup);
|
|
|
|
const resolve4Promise = util.promisify(dns.resolve4);
|
|
|
|
const resolve6Promise = util.promisify(dns.resolve6);
|
|
|
|
const resolveMxPromise = util.promisify(dns.resolveMx);
|
|
|
|
const resolveTxtPromise = util.promisify(dns.resolveTxt);
|
|
|
|
const resolveNsPromise = util.promisify(dns.resolveNs);
|
|
|
|
const resolveCnamePromise = util.promisify(dns.resolveCname);
|
|
|
|
const resolveSoaPromise = util.promisify(dns.resolveSoa);
|
|
|
|
const resolveSrvPromise = util.promisify(dns.resolveSrv);
|
|
|
|
const resolvePtrPromise = util.promisify(dns.resolvePtr);
|
|
|
|
|
|
|
|
const [a, aaaa, mx, txt, ns, cname, soa, srv, ptr] = await Promise.all([
|
|
|
|
lookupPromise(hostname),
|
|
|
|
resolve4Promise(hostname).catch(() => []), // A record
|
|
|
|
resolve6Promise(hostname).catch(() => []), // AAAA record
|
|
|
|
resolveMxPromise(hostname).catch(() => []), // MX record
|
|
|
|
resolveTxtPromise(hostname).catch(() => []), // TXT record
|
|
|
|
resolveNsPromise(hostname).catch(() => []), // NS record
|
|
|
|
resolveCnamePromise(hostname).catch(() => []), // CNAME record
|
|
|
|
resolveSoaPromise(hostname).catch(() => []), // SOA record
|
|
|
|
resolveSrvPromise(hostname).catch(() => []), // SRV record
|
|
|
|
resolvePtrPromise(hostname).catch(() => []) // PTR record
|
|
|
|
]);
|
|
|
|
|
|
|
|
return {
|
2023-08-09 23:33:36 +02:00
|
|
|
A: a,
|
|
|
|
AAAA: aaaa,
|
|
|
|
MX: mx,
|
|
|
|
TXT: txt,
|
|
|
|
NS: ns,
|
|
|
|
CNAME: cname,
|
|
|
|
SOA: soa,
|
|
|
|
SRV: srv,
|
|
|
|
PTR: ptr
|
2023-06-22 16:24:36 +02:00
|
|
|
};
|
|
|
|
} catch (error) {
|
2023-08-09 23:33:36 +02:00
|
|
|
throw new Error(error.message);
|
2023-06-22 16:24:36 +02:00
|
|
|
}
|
|
|
|
};
|
2023-08-09 23:33:36 +02:00
|
|
|
|
2023-09-03 13:27:04 +02:00
|
|
|
module.exports = middleware(handler);
|
|
|
|
module.exports.handler = middleware(handler);
|