Install Node WHOIS globally
masterTo use the whois command directly from your terminal, install the package globally using npm.
$ npm install -g whoisrepository·master·Indexed 42 days ago
https://github.com/furqansoftware/node-whoisA WHOIS client for Node.js version 2.16.2 that allows developers to perform WHOIS lookups for domains and IP addresses via a CLI or a programmatic API. It features automatic server discovery, referral following, SOCKS proxy support, and a verbose mode for tracking referral chains.
To use the whois command directly from your terminal, install the package globally using npm.
$ npm install -g whoisTo use Node WHOIS as a module within your Node.js application, install it locally in your project directory.
$ npm install whoisWhen calling whois.lookup(address, options, callback), you can pass an options object as the second argument to customize the lookup behavior.
Supported keys:
server: A string ("host:port") or an object with host and port keys. If empty, it relies on servers.json.follow: Number of times to follow redirects.timeout: Socket timeout (excluding this does not override default values).verbose: If true, returns an array of responses from all servers.bind: Bind the socket to a local IP address.proxy: An object for SOCKS Proxy configuration containing host, port, and type (integer 4 or 5).whois.lookup('google.com', {
"server": "", // string ("host:port") or { host, port }
"follow": 2, // number of times to follow redirects
"timeout": 0, // socket timeout
"verbose": false, // true returns an array of responses from all servers
"bind": null, // bind to a local IP address
"proxy": { // (optional) SOCKS Proxy
"host": "",
"port": 0,
"type": 5 // or 4
}
}, function(err, data) {
console.log(data)
})Import the whois module and use the lookup method. The method accepts an address and a callback function with the signature function(err, data).
var whois = require('whois')
whois.lookup('google.com', function(err, data) {
console.log(data)
})When calling lookup(addr, options, done), the options object can be used to customize the connection and behavior.
| Option | Type | Default | Description |
|---|---|---|---|
follow | number | 2 | The number of referral servers to follow. |
timeout | number | 60000 | Connection timeout in milliseconds. |
server | string or object | undefined | The WHOIS server to use. Can be a string ('host:port') or an object { host, port, query }. |
proxy | string or object | undefined | SOCKS proxy configuration. Can be a string ('host:port') or an object { host, port, type }. |
punycode | boolean | undefined | Whether to use Punycode for domain names. Set to false when looking up IP addresses. |
encoding | string | undefined | The character encoding for the socket data. |
bind | string | undefined | The local address to bind the socket to. |
verbose | boolean | false | If true, the result is returned as an array of objects containing { server, data } for each step in the referral chain. |
const options = {
follow: 5,
timeout: 30000,
server: 'whois.iana.org:43',
proxy: '127.0.0.1:1080',
verbose: true
};
lookup('example.com', options, (err, data) => {
// ...
});The following options are available for the whois command line interface:
| Option | Flag | Description |
|---|---|---|
--version | Show version number | |
--server | -s | WHOIS server (string host:port or similar) |
--follow | -f | Number of times to follow redirects (default: 0) |
--proxy | -p | SOCKS proxy |
--verbose | -v | Show verbose results (default: false) |
--bind | -b | Bind to a local IP address |
--help | -h | Show help |
Options:
--version Show version number [boolean]
-s, --server whois server [default: null]
-f, --follow number of times to follow redirects [default: 0]
-p, --proxy SOCKS proxy [default: null]
-v, --verbose show verbose results [boolean] [default: false]
-b, --bind bind to a local IP address [default: null]
-h, --help Show help [boolean] [default: false]Once installed globally, you can perform lookups using the whois command followed by an address (domain or IP).
Command Syntax:
whois [options] address
whois [options] addressThe lookup function is the primary entry point for performing WHOIS queries. It accepts a target address (domain or IP), an optional configuration object, and a callback function.
Key Features:
follow option) to reach the authoritative WHOIS server.options.verbose is set to true, the callback returns an array of objects containing the server host and the raw data from each step in the referral chain, rather than just the final string.Arguments:
addr (string): The domain name, IP address, or target to look up. Note: email addresses are not supported.options (object, optional): Configuration settings (see Configure lookup options).done (function): A callback function called with (err, data). If options is omitted, this must be provided.import { lookup } from 'node-whois';
// Basic usage
lookup('google.com', (err, data) => {
if (err) {
console.error(err);
return;
}
console.log(data);
});
// Usage with options
lookup('google.com', { timeout: 10000, verbose: true }, (err, parts) => {
if (err) return console.error(err);
// If verbose is true, 'parts' is an array of { server, data } objects
console.log(parts);
});The following flags are available for the whois command to customize the lookup behavior:
| Flag | Alias | Description |
|---|---|---|
--server | -s | Specify a specific WHOIS server to query. |
--follow | -f | The number of times to follow redirects (default: 0). |
--timeout | -t | Socket timeout in milliseconds (default: 60000). |
--proxy | -p | SOCKS proxy to use. |
--verbose | -v | Show verbose results. |
--bind | -b | Bind to a specific local IP address. |
--help | -h | Display the help message. |
# Example using a specific server and following redirects
whois -s whois.verisign-grs.com -f 1 google.com
# Example using a proxy and a custom timeout
whois -p localhost:1080 -t 30000 example.comThe module exports a SERVERS object containing a mapping of TLDs and IP information to their respective WHOIS server configurations. This is used internally for automatic server discovery when no server option is provided.
import { SERVERS } from 'node-whois';