Last active
February 6, 2025 15:43
-
-
Save modulsx/6394bc1975381420bf05a9a557013679 to your computer and use it in GitHub Desktop.
Fast DNS Record Checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { argv } = require('node:process'); | |
const dns = require('node:dns').promises; | |
const ALLOWED_RECORD_TYPES = ['A', 'AAAA', 'ANY', 'CAA', 'CNAME', 'MX', 'NS', 'NAPTR', 'PTR', 'SOA', 'SRV', 'TXT'] | |
async function checkDNSRecord(domain, value, recordType = 'A'){ | |
return new Promise(async (resolve, _) => { | |
try{ | |
const resolver = new dns.Resolver(); | |
const apexDomain = domain.split('.').splice(-2).join('.') | |
const nsRecords = await resolver.resolve(apexDomain, 'NS') | |
const nsServerIps = await Promise.all(nsRecords.map(nsRecord => { return resolver.resolve(nsRecord, 'A')})) | |
resolver.setServers(nsServerIps.flat()) | |
const records = await resolver.resolve(domain, recordType) | |
console.log(records) | |
resolve(records.includes(value)) | |
} | |
catch(err){ | |
console.log(err) | |
resolve(false) | |
} | |
}) | |
} | |
(async() => { | |
const domain = argv[2] | |
const value = argv[3] | |
if(!domain || !value){ | |
throw new Error(`Domain and Value arguments are required`) | |
} | |
const recordType = argv[4] | |
if(recordType && !ALLOWED_RECORD_TYPES.includes(recordType)){ | |
throw new Error(`Record type not allowed. Valid types are ${ALLOWED_RECORD_TYPES.join(', ')}`) | |
} | |
const isRecordMatch = await checkDNSRecord(domain, value, recordType) | |
console.log(isRecordMatch) | |
})() | |
// usage : node fast-dns-checker.js <domain> <record-value> <record-type> | |
// example : node fast-dns-checker.js dukn.site 192.0.0.1 A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment