Skip to content

Commit

Permalink
Merge pull request #111 from popeeyy/tr-cctld
Browse files Browse the repository at this point in the history
Add .tr WHOIS server & parsing
  • Loading branch information
AndreiIgna authored Aug 4, 2024
2 parents 67c74ac + 9c4b504 commit 142ba40
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
66 changes: 60 additions & 6 deletions src/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
'redacted for gdpr',
'redacted redacted',
'not available from registry',
'hidden upon user request',
]

// WHOIS labels to rename. "From" must be lowercase
Expand All @@ -165,6 +166,7 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
hostname: 'Name Server',
'domain nameservers': 'Name Server',
'domain servers in listed order': 'Name Server', // found in .ly
'domain servers': 'Name Server', // found in .tr
'name servers dns': 'Name Server', // found in .mx
flags: 'Domain Status',
status: 'Domain Status',
Expand All @@ -179,6 +181,7 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
'registrar............': 'Registrar', // found in .ax
'record maintained by': 'Registrar',
'sponsoring registrar': 'Registrar',
'registrar organization name': 'Registrar', // found in .tr
url: 'Registrar URL',
'registrar website': 'Registrar URL',
'registrar web': 'Registrar URL', // found in .it
Expand All @@ -190,6 +193,7 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
'relevant dates registered on': 'Created Date',
created: 'Created Date',
'created on': 'Created Date', // found in .mx
'additional info created on..............': 'Created Date', // found in .tr
'registration time': 'Created Date',
registered: 'Created Date',
'created..............': 'Created Date', // found in .ax
Expand All @@ -213,6 +217,7 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
'expire date': 'Expiry Date',
'expiration date': 'Expiry Date',
'expires..............': 'Expiry Date', // found in .ax
'additional info expires on..............': 'Expiry Date', // found in .tr
'paid-till': 'Expiry Date',
'expiry date': 'Expiry Date',
expire: 'Expiry Date',
Expand All @@ -223,18 +228,18 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
registrant: 'Registrant Name', // found in .ai
'registrant contact': 'Registrant Name',
'registrant contact name': 'Registrant Name',
'registrantname': 'Registrant Name', // found in .ai
registrantname: 'Registrant Name', // found in .ai
'registrant person': 'Registrant Name', // found in .ua
'registrant email': 'Registrant Email', // found in .ua
'registrant e-mail': 'Registrant Email', // found in .fr
'registrant contact email': 'Registrant Email',
'registrantemail': 'Registrant Email', // found in .ai
'registrantstreet': 'Registrant Street', // found in .ai
'registrantcity': 'Registrant City', // found in .ai
'registrantcountry': 'Registrant Country', // found in .ai
registrantemail: 'Registrant Email', // found in .ai
registrantstreet: 'Registrant Street', // found in .ai
registrantcity: 'Registrant City', // found in .ai
registrantcountry: 'Registrant Country', // found in .ai
'registrant country': 'Registrant Country', // found in .fr
'registrant organisation': 'Registrant Organization',
'registrantphone': 'Registrant Phone',
registrantphone: 'Registrant Phone',
'trading as': 'Registrant Organization', // found in .uk, .co.uk
org: 'Registrant Organization', // found in .ru
'registrant state': 'Registrant State/Province',
Expand Down Expand Up @@ -320,6 +325,10 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
lines = handleDotFr(lines)
}

if (domain.endsWith('.tr')) {
lines = handleDotTr(lines)
}

lines = lines.map((l) => l.trim())

lines.forEach((line) => {
Expand Down Expand Up @@ -380,6 +389,51 @@ const parseDomainWhois = (domain, whois, ignorePrivacy) => {
return data
}

const handleDotTr = (lines) => {
lines = lines.filter((line) => line.trim() !== '') // Remove blank lines

const registrantLines = ['Name', undefined, undefined, undefined, undefined] // No clue what the other 4 fields are, all domains have them hidden
const replacement = []
let section = ''
let sectionLine = 0

for (let line of lines) {
line = line.replace(/\s+/g, ' ').replace(' :', ':').trim()

if (line.startsWith('** Domain')) {
// Keep line for domain name/nameservers
line = line.replace('** ', '')
} else if (line.includes('** ')) {
// Start new section
section = line.replace(':', '').replace('** ', '').trim()
sectionLine = 0
continue
} else if (section === 'Registrant') {
// Add registrant info
if (!registrantLines[sectionLine]) continue

line = `Registrant ${registrantLines[sectionLine]}: ${line}`
sectionLine++
} else if (!line.includes(': ')) {
// Add multi-line information to one line (nameservers and address)
replacement[replacement.length - 1] += ` ${line}`
continue
} else if (section) {
// Append section name to each line
line = `${section} ${line}`
}

// Remove period at end of dates
if (section === 'Additional Info') {
line = line.replace(/\.$/, '')
}

replacement.push(line)
}

return replacement
}

const handleDotUa = (lines) => {
const types = ['Registrar', 'Registrant', 'Admin', 'Technical']
let flag = ''
Expand Down
2 changes: 1 addition & 1 deletion src/whoiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let cacheTldWhoisServer = {
ro: 'whois.rotld.ro',
rs: 'whois.rnids.rs',
so: 'whois.nic.so',
tr: 'whois.nic.tr',
us: 'whois.nic.us',
ws: 'whois.website.ws',

Expand Down Expand Up @@ -102,7 +103,6 @@ const whoisTld = async (query, { timeout = 15000, raw = false, domainTld = '' }

// if no whois server found, search in more sources
if (!data.whois) {

//todo
// instead of using `domainTld`, split `query` in domain parts and request info for all tld combinations
// example: query="example.com.tld" make 3 requests for "example.com.tld" / "com.tld" / "tld"
Expand Down
9 changes: 9 additions & 0 deletions test/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ describe('#whoiser.domain()', function() {
assert.equal(typeof whois['whois.nic.it'][label], 'string', `${label} does not exist, or is not a string`)
}
})

it('returns WHOIS for "trabis.gov.tr"', async function () {
let whois = await whoiser.domain('trabis.gov.tr')
assert.equal(whois['whois.nic.tr']['Domain Name'], 'trabis.gov.tr', 'Domain name doesn\'t match')
assert.equal(whois['whois.nic.tr']['Name Server'].length, 5, 'Incorrect number of NS returned')
assert.equal(whois['whois.nic.tr']['Registrar'], 'TRABİS KK', 'Registrar name doesn\'t match')
assert.equal(whois['whois.nic.tr']['Registrant Name'], 'Bilgi Teknolojileri ve İletişim Kurumu', 'Registrant name doesn\'t match')
assert.equal(whois['whois.nic.tr']['Created Date'], '2011-Mar-22', 'Creation date doesn\'t match')
})
});

});

0 comments on commit 142ba40

Please sign in to comment.