whoiser

repository·master·Indexed 42 days ago

https://github.com/layeredstudio/whoiser

A Node.js WHOIS client providing a unified interface for querying WHOIS data for domains, TLDs, IP addresses, and AS numbers. Version 2.0.0-beta.10 features automatic server discovery and minimal parsing to ensure consistent data formats across different WHOIS providers.

Tokens
3.3K
Snippets
14
Records
16
Agent score
54%

What's inside whoiser

  1. Note on Unsupported TLDs (.ch)

    master
    The .ch TLD is currently unsupported for full WHOIS data retrieval because its WHOIS server does not return standard WHOIS info via typical protocols (it is primarily browser-based). You can only use this library to check .ch domain availability.
  2. Get WHOIS data for any internet address with whoiser()

    master

    The whoiser(query, options) method is a convenience function that automatically recognizes the query type (domain, TLD, IP, or ASN) and routes the request to the correct WHOIS server. It requires zero configuration but accepts an options object for customization.

    const whoiser = require('whoiser')
    
    const domainWhois = whoiser('google.com')
    const tldWhois = whoiser('.net')
    const ipWhois = whoiser('1.1.1.1')
  3. Get WHOIS info for IPs using whoiser.ip()

    master

    Use whoiser.ip(ip, options) to retrieve WHOIS information for an IP address.

    Options:

    • host: WHOIS server to query. Default: WHOIS server from IANA.
    • timeout: WHOIS server request timeout in ms. Default: 1500.
    • raw: If true, the raw WHOIS result is added to the __raw key in the response.

    Returns: A Promise resolving to an Object containing parsed IP WHOIS information (e.g., range, route, asn, Organization).

    const whoiser = require('whoiser');
    
    (async () => {
    	// WHOIS info with auto-discovering for WHOIS server
    	let ipInfo = await whoiser('1.1.1.1')
    
    	// OR with options for whois server
    	let ipInfo2 = await whoiser.ip('8.8.8.8', {host: 'whois.arin.net'})
    
    	console.log(ipInfo, ipInfo2)
    })();
  4. Get WHOIS info for AS numbers using whoiser.asn()

    master

    Use whoiser.asn(asn, options) to retrieve WHOIS information for an Autonomous System (AS) number. The asn can be provided as a string (e.g., 'AS15169') or a number (e.g., 15169).

    Options:

    • host: WHOIS server to query. Default: WHOIS server from IANA.
    • timeout: WHOIS server request timeout in ms. Default: 1500.
    • raw: If true, the raw WHOIS result is added to the __raw key in the response.

    Returns: A Promise resolving to an Object containing parsed ASN information (e.g., ASNumber, ASName, RegDate).

    const whoiser = require('whoiser');
    
    (async () => {
    	// WHOIS info for ASN15169
    	let whois = await whoiser.asn(15169)
    
    	console.log(whois)
    })();
  5. Get WHOIS info for domains using whoiser.domain()

    master

    Use whoiser.domain(domain, options) to retrieve parsed WHOIS data for a specific domain. The domain argument should be the domain name excluding subdomains (e.g., 'google.com').

    Options:

    • host: WHOIS server to query. Default: WHOIS server from IANA.
    • timeout: WHOIS server request timeout in ms. Default: 1500.
    • follow: Number of WHOIS servers to query. 1 queries only the registry server (faster); 2 queries both registry and registrar (more details). Default: 2.
    • raw: If true, the raw WHOIS result is added to the __raw key in the response.
    • ignorePrivacy: Boolean to show or hide WHOIS protected data. Default: true.

    Returns: A Promise resolving to an Object where keys are the WHOIS servers checked and values are the parsed WHOIS data objects.

    const whoiser = require('whoiser');
    
    (async () => {
    	// WHOIS info from Registry (Verisign) AND Registrar (MarkMonitor) whois servers
    	let domainInfo = await whoiser('google.com')
    
    	// OR with options for whois server and how many WHOIS servers to query
    	let domainInfo2 = await whoiser.domain('blog.google', {host: 'whois.nic.google', follow: 1})
    
    	console.log(domainInfo, domainInfo2)
    })();
  6. Reference: Client API Methods

    master

    The following methods are available on the whoiser client:

    • whoiser(query, options): Get WHOIS data for any internet address.
    • whoiser.domain(domain, options): Get parsed WHOIS data for a domain.
    • whoiser.tld(tld, options): Get WHOIS data for a TLD.
    • whoiser.asn(asn, options): Get WHOIS data for an AS number.
    • whoiser.ip(ip, options): Get WHOIS data for an IP.
    • whoiser.allTlds: Returns a list of all TLDs (downloaded from IANA).
    • whoiser.query(options): Query a specific WHOIS server for data.
  7. Configure Domain WHOIS query options

    master

    When performing a domain WHOIS lookup, you can provide a DomainWhoisOptions object to customize the request behavior. Key options include:

    • host: Specify a custom WHOIS server host.
    • timeout: Set a timeout in milliseconds.
    • follow: Control how many redirects to follow (values 1 or 2).
    • raw: If true, returns the raw response.
    • ignorePrivacy: Whether to attempt to bypass privacy protections.
    • whoisQuery: A custom function (host: string, query: string, timeout?: number) => Promise<string> to override the default WHOIS query mechanism.
    const options: DomainWhoisOptions = {
      host: 'whois.example.com',
      timeout: 5000,
      follow: 1,
      raw: false,
      ignorePrivacy: true,
      whoisQuery: async (host, query, timeout) => {
        // Custom implementation
        return 'custom response';
      }
    };
  8. Query TLD information with `whoisTld()`

    master

    Use whoisTld(tld, timeout) to retrieve information about a Top-Level Domain (TLD) from the IANA WHOIS server.

    Parameters:

    • tld: (string) The TLD or SLD to query (e.g., 'com' or '.co.uk').
    • timeout: (number) Timeout in milliseconds. Defaults to 1000.

    Returns a TldWhoisResponse object containing normalized TLD data such as organisation, contacts, nserver, status, and whois (the registry's WHOIS server).

    import { whoisTld } from 'whoiser';
    
    try {
      const tldData = await whoisTld('com');
      console.log(tldData.whois); // The registry WHOIS server
    } catch (err) {
      console.error('TLD not found or invalid:', err.message);
    }
  9. Extract the primary result from `whoisDomain()` with `firstResult()`

    master

    Because whoisDomain() returns a DomainWhois object (a dictionary where keys are the WHOIS server hostnames and values are the parsed results), you often only want the data from the first/primary server queried. Use firstResult(whoisResults) to extract the DomainWhoisData from the first entry in the results object.

    import { whoisDomain, firstResult } from 'whoiser';
    
    const results = await whoisDomain('example.com');
    const data = firstResult(results);
    // 'data' is now a DomainWhoisData object instead of a DomainWhois map
  10. Query WHOIS data for an IP address with `whoisIp()`

    master

    Use whoisIp(ip, options) to retrieve WHOIS information for an IP address. The function first queries the IANA WHOIS server to locate the appropriate authoritative WHOIS server for the given IP.

    Options:

    • host: (string) Override the discovered WHOIS server.
    • timeout: (number) Timeout in milliseconds for the query.

    Returns a WhoisData object containing the parsed WHOIS information.

    import { whoisIp } from 'whoiser';
    
    try {
      const data = await whoisIp('192.0.2.1');
      console.log(data);
    } catch (err) {
      console.error('Failed to query IP:', err.message);
    }
  11. Query WHOIS data for an ASN with `whoisAsn()`

    master

    Use whoisAsn(asn, options) to retrieve WHOIS information for an Autonomous System Number (ASN).

    Parameters:

    • asn: (number) The ASN to query (must be between 0 and 4294967295).

    Options:

    • host: (string) Override the discovered WHOIS server.
    • timeout: (number) Timeout in milliseconds for the query.

    Returns a WhoisData object containing the parsed WHOIS information.

    import { whoisAsn } from 'whoiser';
    
    try {
      const data = await whoisAsn(12345);
      console.log(data);
    } catch (err) {
      console.error('Failed to query ASN:', err.message);
    }