Skip to content

Commit

Permalink
Added
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiIgna committed Aug 6, 2019
1 parent ff8b75e commit 940aab0
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Uses `dig` command to make DNS requests, has a built-in list of subdomains to te
Aiming to have these features:
- [x] Retrieve DNS records for a domain -> `dnsRecords.getDnsRecords()`
- [x] Discover common subdomains for a domain -> `dnsRecords.getAllRecords()`
- [ ] Test that all NS respond with same info
- [ ] Test that all NS respond with same info, with extra info: response time, NameServer location & ISP

## Getting Started

Expand Down Expand Up @@ -97,6 +97,40 @@ Returns a promise which resolves with an `Array` of records found, grouped by ty
}
```

**Test NS servers for a domain**
```js
const dnsRecords = require('./index.js');

(async () => {

// Discover NS info
const NSRecords = await dnsRecords.getNameServers('fb.com')
console.log('NS servers info', NSRecords)

})()
```
Returns a promise which resolves with an `Array` of NS info:
```js
[
{
ns: 'a.ns.facebook.com.',
soaSerial: '1565080527',
IPv4: [ '69.171.239.12' ],
IPv6: [ '2a03:2880:fffe:c:face:b00c::35' ],
responseTimev4: '',
responseTimev6: ''
},
{
ns: 'b.ns.facebook.com.',
soaSerial: '1565080527',
IPv4: [ '69.171.255.12' ],
IPv6: [ '2a03:2880:ffff:c:face:b00c::35' ],
responseTimev4: '',
responseTimev6: ''
}
]
```

## More

Please report any issues here on GitHub.
Expand Down
53 changes: 53 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,58 @@ const getDnsRecords = async (names, types, server) => {
return re
}


const getNameServers = async domain => {
let ns = []

if (!isDomain(domain)) {
throw new Error(`"${domain}" is not a valid domain name`)
}

const nameServers = await getDnsRecords(domain, 'NS')

if (!nameServers.length) {
throw new Error(`No name servers found for "${domain}"`)
}

nameServers.forEach(nameServer => {
ns.push({
ns: nameServer.value,
soaSerial: '',
IPv4: [],
IPv6: [],
responseTimev4: '',
responseTimev6: ''
})
})


// 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 A = await Promise.all(ns.map(nameServer => getDnsRecords(nameServer.ns, ['A', 'AAAA'])))
A.forEach((records, index) => {
records.forEach(record => {
const ip = record.type === 'A' ? 'IPv4' : 'IPv6'
ns[index][ip].push(record.value)
})
})


// TODO get IPs response time
// https://wp-rocket.me/blog/test-dns-server-response-time-troubleshoot-site-speed/


return ns
}


const getAllRecords = async domain => {
let dns = {
NS: [],
Expand Down Expand Up @@ -195,5 +247,6 @@ const getAllRecords = async domain => {

module.exports = {
getDnsRecords,
getNameServers,
getAllRecords
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@layered/dns-records",
"version": "1.0.0",
"version": "1.1.0",
"description": "Discover publicly available DNS Records for a domain",
"keywords": [
"dns",
Expand Down

0 comments on commit 940aab0

Please sign in to comment.