diff --git a/index.d.ts b/index.d.ts index 1a52004..4c14d61 100644 --- a/index.d.ts +++ b/index.d.ts @@ -14,6 +14,8 @@ declare module 'whoiser' { */ timeout?: number + encoding?: string + /** * How many WHOIS server to query. * 1 = registry server (faster), diff --git a/src/whoiser.js b/src/whoiser.js index eb2b7f4..7e6a796 100644 --- a/src/whoiser.js +++ b/src/whoiser.js @@ -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')))