Node WHOIS

repository·master·Indexed 42 days ago

https://github.com/furqansoftware/node-whois

A 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.

Tokens
2.2K
Snippets
10
Records
10
Agent score
53%

What's inside Node WHOIS

  1. Configure lookup behavior with options object

    master

    When 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)
    })
  2. Perform a WHOIS lookup using the Node.js API

    master

    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)
    })
  3. Configure lookup options

    master

    When calling lookup(addr, options, done), the options object can be used to customize the connection and behavior.

    OptionTypeDefaultDescription
    follownumber2The number of referral servers to follow.
    timeoutnumber60000Connection timeout in milliseconds.
    serverstring or objectundefinedThe WHOIS server to use. Can be a string ('host:port') or an object { host, port, query }.
    proxystring or objectundefinedSOCKS proxy configuration. Can be a string ('host:port') or an object { host, port, type }.
    punycodebooleanundefinedWhether to use Punycode for domain names. Set to false when looking up IP addresses.
    encodingstringundefinedThe character encoding for the socket data.
    bindstringundefinedThe local address to bind the socket to.
    verbosebooleanfalseIf 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) => {
      // ...
    });
  4. Reference CLI options for WHOIS

    master

    The following options are available for the whois command line interface:

    OptionFlagDescription
    --versionShow version number
    --server-sWHOIS server (string host:port or similar)
    --follow-fNumber of times to follow redirects (default: 0)
    --proxy-pSOCKS proxy
    --verbose-vShow verbose results (default: false)
    --bind-bBind to a local IP address
    --help-hShow 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]
  5. Perform WHOIS lookups with lookup()

    master

    The 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:

    • Automatic Server Discovery: If no server is provided, the library automatically determines the correct WHOIS server based on the TLD or IP address.
    • Referral Following: By default, the library follows up to 2 referrals (using the follow option) to reach the authoritative WHOIS server.
    • Proxy Support: Supports SOCKS proxies for connections.
    • Verbose Mode: When 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);
    });
  6. Reference the whois CLI flags

    master

    The following flags are available for the whois command to customize the lookup behavior:

    FlagAliasDescription
    --server-sSpecify a specific WHOIS server to query.
    --follow-fThe number of times to follow redirects (default: 0).
    --timeout-tSocket timeout in milliseconds (default: 60000).
    --proxy-pSOCKS proxy to use.
    --verbose-vShow verbose results.
    --bind-bBind to a specific local IP address.
    --help-hDisplay 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.com
  7. Exported SERVERS registry

    master

    The 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';