Skip to content

Commit

Permalink
Update - consistent label for Domain whois NS
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Igna committed Feb 13, 2019
1 parent 5483d7b commit f6de708
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
26 changes: 18 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,19 @@ const whoisDomain = async (domain, {host = null, timeout = 15000, follow = 2} =


const parseDomainWhois = whois => {
const shouldBeArray = ['Domain Status', 'Name Server', 'Nameserver', 'Nserver', 'nserver', 'Name servers'];
const renameLabels = {
'nameserver': 'Name Server',
'nserver': 'Name Server',
'name servers': 'Name Server'
};
const ignoreLabels = ['note', 'notes', 'please note', 'important', 'notice', 'terms of use', 'web-based whois', 'https', 'to', 'registration service provider'];
const ignoreTexts = ['more information', 'lawful purposes', 'to contact', 'use this data', 'register your domain', 'copy and paste', 'find out more', 'this', 'please', 'important', 'prices', 'payment', 'you agree', 'terms'];

let text = [];
let data = {};
let data = {
'Domain Status': [],
'Name Server': []
};
let lines = whois.trim().split('\n').map(line => line.trim());

// Fix "label: \n value" format
Expand All @@ -179,13 +186,14 @@ const parseDomainWhois = whois => {
lines.forEach(line => {

if ((line.includes(': ') || line.endsWith(':')) && !line.startsWith('%')) {
const [label, value] = splitStringBy(line, line.indexOf(':')).map(info => info.trim())
let [label, value] = splitStringBy(line, line.indexOf(':')).map(info => info.trim())

if (shouldBeArray.includes(label)) {
if (value) {
data[label] = data[label] || [];
data[label].push(value);
}
if (renameLabels[label.toLowerCase()]) {
label = renameLabels[label.toLowerCase()]
}

if (data[label] && Array.isArray(data[label])) {
data[label].push(value);
} else if (!ignoreLabels.includes(label.toLowerCase()) && !ignoreTexts.some(text => label.toLowerCase().includes(text))) {
data[label] = data[label] ? data[label] + ' ' + value : value;
} else {
Expand All @@ -197,6 +205,8 @@ const parseDomainWhois = whois => {

});

// remove invalid Name Servers (not valid hostname)
data['Name Server'] = data['Name Server'].filter(nameServer => validator.isFQDN(nameServer))

// remove multiple empty lines
text = text.join("\n").trim();
Expand Down
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": "whoiser",
"version": "1.2.0",
"version": "1.2.1",
"description": "Whois info for TLDs, domains and IPs",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Whoiser', function() {
it('should return WHOIS for "google.eu" when whois data is "label:_EOL_value"', async function() {
let whois = await whoiser.domain('google.eu', {follow: 1})
assert.equal(whois['whois.eu']['Domain'], 'google.eu', 'Domain name doesn\'t match')
assert.notStrictEqual(whois['whois.eu']['Name servers'].length, 0, 'Does not return NS')
assert.notStrictEqual(whois['whois.eu']['Name Server'].length, 0, 'Does not return NS')
});

it('should return WHOIS for "mañana.com" - IDN', async function() {
Expand Down

0 comments on commit f6de708

Please sign in to comment.