Skip to content

Commit

Permalink
Updated - remove ending dot from domains
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiIgna committed Dec 9, 2021
1 parent 6108e4e commit 0c0fb72
Show file tree
Hide file tree
Showing 4 changed files with 949 additions and 14 deletions.
22 changes: 12 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ const getDnsRecords = async (names, types, server) => {
// replace tab(s) with space split by space
line = line.replace(/[\t]+/g, " ").split(" ")

let value = line.slice(4).join(" ")

if (['NS', 'MX', 'A', 'AAAA', 'CNAME'].includes(line[3]) && value.endsWith('.') && isDomain(value)) {
value = value.slice(0, -1)
}

return {
name: line[0],
name: line[0].slice(0, -1),
ttl: line[1],
type: line[3],
value: line.slice(4).join(" ")
value
}
})

Expand Down Expand Up @@ -150,15 +156,13 @@ const getNameServers = async domain => {
})
})


// get SOA Record
// get SOA Record
const SOA = await Promise.all(ns.map(nameServer => getDnsRecords(domain, 'SOA', nameServer.ns)))
SOA.forEach((records, index) => {
const soaRecord = records[0].value.split(' ')
ns[index].soaSerial = soaRecord[2]
})


// get A/AAAA Records
const ips = []
const A = await Promise.all(ns.map(nameServer => getDnsRecords(nameServer.ns, ['A', 'AAAA'])))
Expand All @@ -170,7 +174,6 @@ const getNameServers = async domain => {
})
})


// Get NS IPs response time
const times = await Promise.all(ips.map(ip => getDnsTime(domain, ip)))

Expand All @@ -187,7 +190,6 @@ const getNameServers = async domain => {
return record
})


return ns
}

Expand Down Expand Up @@ -219,15 +221,15 @@ const getAllRecords = async domain => {
}


// check if result can be grouped under wildcard
// helper - check if result can be grouped under wildcard
const isNotWildcardSubdomain = result => {
return !wildcardSubdomains.includes(result.type + '-' + result.value)
}

// filter DNS results to only allow those for requested domain
// helper - filter DNS results to only allow those for requested domain
const cleanResults = result => {
return isDomain(result.name) // is valid domain
&& result.name.endsWith(`${domain}.`) // is for requested domain
&& result.name.endsWith(domain) // is for requested domain
&& isNotWildcardSubdomain(result) // is not a match for wildcard CNAME
}

Expand Down
Loading

0 comments on commit 0c0fb72

Please sign in to comment.