Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare module 'whoiser' {
*/
timeout?: number

encoding?: string

/**
* How many WHOIS server to query.
* 1 = registry server (faster),
Expand Down
3 changes: 2 additions & 1 deletion src/whoiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ const whoisHostToIp = {
'whois.google.com': '216.239.34.22',
}

const whoisQuery = ({ host = null, port = 43, timeout = 15000, query = '', querySuffix = '\r\n' } = {}) => {
const whoisQuery = ({ host = null, port = 43, timeout = 15000, encoding = '', query = '', querySuffix = '\r\n' } = {}) => {
return new Promise((resolve, reject) => {
let data = ''
const socket = net.connect({ host, port }, () => socket.write(query + querySuffix))
socket.setTimeout(timeout)
if (encoding) socket.setEncoding(encoding)
socket.on('data', (chunk) => (data += chunk))
socket.on('close', (hadError) => resolve(data))
socket.on('timeout', () => socket.destroy(new Error('Timeout')))
Expand Down