npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@triaxio/node-xwhois

v2.2.3

Published

Advanced whois library with extended capabilities.

Downloads

19

Readme

Description

Library can get various network information about domain names and IP-addresses.

Currently it provides the following information:

  • whois (currently using node-whois library)
  • BGP information (AS number and name)
  • define whether IP address is TOR node either exit node, or entry node, or other
  • DNS information
  • GeoLocation information simultaneously using MaxMind and IP2Location databases

Installation

You can install it with this command:

npm install node-xwhois

Usage

Simplest way to get all possible information about domain name or IP address is using hostInfo() function:

'use strict'
const whois = require('node-xwhois');

const host1 = 'xinit.ru';
const host2 = '8.8.8.8';

whois.geoInit('test/GeoIP')
.then(() => {
    whois.hostInfo(host1)
    .then(data => console.log(`${host1} info:\n`, JSON.stringify(data, null, 4)))
    .catch(err => console.log(err));

    whois.hostInfo(host2)
    .then(data => console.log(`${host2} info:\n`, JSON.stringify(data, null, 4)))
    .catch(err => console.log(err));
})
.catch(err => console.log(err));

All asynchronous functions in this library return Promises.

Documentation

ip2long(ip)

A JavaScript equivalent of PHP's ip2long(). Convert IPv4 address in dotted notation to 32-bit long integer. You can pass IP in all possible representations, i.e.:

192.0.34.166
0xC0.0x00.0x02.0xEB
0xC00002EB
3221226219
0.0xABCDEF
255.255.255.256
0300.0000.0002.0353
030000001353

Parameters

ip String. IPv4-address in one of possible representations.

Return

32-bit number notation of IP-address expressed in decimal.

isIP(host)

Detect if host is correct IP-address. Internally uses net.isIP().

Parameters

host String to test.

Return

true if host is correct IP address or false otherwise.

isDomain(host)

Detect if host is correct domain name. It can't test IDN's. And it can't define if domain name is really exist or can exist. This function just performs syntax check.

Parameters

host String to test.

Return

True if host is correct domain name false otherwise.

reverse(ip)

Define domain names by IP-address using reverse domain request.

Parameters

ip IP-address to reverse.

Return

Promise where then() takes function with array of hostnames.

Example

const host = '8.8.8.8';

whois.reverse(host)
.then(hostnames => console.log(`${host} reverse:\n`, JSON.stringify(hostnames, null, 4)))
.catch(err => console.log(err));

nslookup(host)

Get host info of domain name like host -a command.

Parameters

host Domain name.

Return

Promise where then() takes function with object like this:

{
    'A'    : ['IPv4-addresses'],
    'AAAA' : ['IPv6-addresses'],
    'MX'   : ['MX-records'    ],
    'TXT'  : ['TXT-records'   ],
    'SRV'  : ['SRV-records'   ],
    'NS'   : ['NS-records'    ],
    'CNAME': ['CNAME-records' ],
    'SOA'  : ['SOA-records'   ]
}

Example

const host = 'xinit.co';

whois.nslookup(host)
.then(info => console.log(`${host} nslookup:\n`, JSON.stringify(info, null, 4)))
.catch(err => console.log(err));

whois(host)

Perform whois request.

Parameters

host Domain name or IP-address.

Return

Promise where then() takes function with whois text.

Example

const host = 'xinit.co';

whois.whois(host)
.then(info => console.log(`${host} whois:\n`, JSON.stringify(info, null, 4)))
.catch(err => console.log(err));

torInfo(ip)

Check if IP address is a TOR node.

Parameters

ip IP-address.

Return

Promise where then() takes function with object like this:

{
    'nodename': 'Name of TOR node',
    'port'    : [0, 0],  // port numbers of TOR node
    'exitNode': true     // if true then this is exit node
}

If IP does not belong to TOR node then null will be passed instead of described object.

Example

const host = '199.87.154.255';

whois.torInfo(host)
.then(info => console.log(`${host} torInfo:\n`, JSON.stringify(info, null, 4)))
.catch(err => console.log(err));

extractIP(str)

Extract IP-addresses from raw text. If some IP-address appears in str multiple times then it will be returned in answer only once.

Parameters

str String to extract IP-addresses from.

Return

Promise where then() takes function with array of IP-addresses as strings.

Example

const ipStr = `
    test raw text test raw text
    77.109.141.140    (37.187.130.68)   ++   188.40.143.7   $$   95.174.227.96 test raw text
    test raw text test raw text test raw text test raw text
    2001:0db8:11a3:09d7:1f34:8a2e:07a0:765d    test raw text test raw text
    2001:0db8:0000:0000:0000:0000:ae21:ad12
    test raw text
    188.40.143.7 188.40.143.7
`;

whois.extractIP(ipStr)
.then(info => console.log('extractIP:\n', JSON.stringify(info, null, 4)))
.catch(err => console.log(err));

geoInit(dbPath)

Initialize script to get GeoLocation information. You need to call this function before using geoInfo() or hostInfo().

Parameters

dbPath Path to directory where GeoLocation DB-files located.

You need to download GeoLocation databases by yourself or using geoUpdate().

If you will download it manually you should get following files: GeoLite2-City.mmdb and GeoLite2-ASN.mmdb from MaxMind IP2LOCATION-LITE-DB5.IPV6.BIN and IP2PROXY-LITE-PX4.BIN from IP2Location

Return

Promise without any parameters. Run geoInfo() only within then() of this Promise to be sure that all GeoLocation DB properly loaded.

geoInfo(host)

Get GeoLocation information.

Parameters

host IP address to get info about.

Return

Promise where then() has object as parameter like in this example:

{
    ip          : '78.46.112.219',
    asn         : '24940',
    as_org      : 'Hetzner Online GmbH',
    proxy       : 'VPN', // see https://www.ip2proxy.com/ for possible values
    country_code: ['DE'],
    country     : ['Germany'],
    region      : [ 'Bayern', 'Bavaria', 'Sachsen' ],
    city        : [ 'Nürnberg', 'Nuremberg', 'Falkenstein' ],
    country_ru  : 'Германия',
    region_ru   : 'Бавария',
    city_ru     : 'Нюрнберг',
    timezone    : 'Europe/Berlin',
    coords      : [
        { lat: 49.4478, lon: 11.068299999999994 },
        { lat: 49.4478, lon: 11.0683 }
    ]
}

Example

const host = '199.87.154.255';

whois.geoInit('test/GeoIP')
.then(() => {
    return whois.geoInfo(host);
})
.then(info => {
    console.log(`${host} geoInfo:\n`, info)
})
.catch(err => console.log(err));

geoUpdate(dbPath, token)

Update MaxMind and IP2Location databases.

Parameters

dbPath Full local path to store DB files.

token API token to download IP2Location database. You should register on https://www.ip2location.com/ to get it.

Return

Promise without any parameters.

Example

const path  = './GeoIP';
const token = 'insert your token here';

whois.geoUpdate(path, token)
.then(() => {
    console.log('OK');
})
.catch(err => {
    console.log('ERROR');
    console.log(err);
});

bgpInfo(host)

Get BGP information, such as Autonomous System number. You can get this info manually by using this command in Linux console:

$ echo "-c -r -a -u -p 109.111.139.45" | nc whois.cymru.com 43

Parameters

host IP address to get info about.

Return

Promise with array of the following objects in then():

[{
    "as": "18451",
    "ip": "199.87.154.255",
    "prefix": "199.87.152.0/21",
    "country_code": "CA",
    "registry": "arin",
    "allocation_date": "2011-01-31",
    "name": "ASN-LES - LES.NET,CA"
}]

Example

const host = '199.87.154.255';

whois.bgpInfo(host)
.then(info => console.log(`${host} bgpInfo:\n`, JSON.stringify(info, null, 4)))
.catch(err => console.log(err));

info(host)

Get all possible information about domain name or IP-address.

Parameters

host Domain name or IP-address.

Return

Promise where then() has the following object as parameter:

{
    host    : host,
    isIP    : true,
    longIP  : null,
    reverse : null,
    geoInfo : null,
    torInfo : null,
    bgpInfo : null,
    isDomain: false,
    nslookup: null,
    whois   : null
}

Example

const host1 = 'xinit.co';
const host2 = '8.8.8.8';

whois.geoInit('test/GeoIP')
.then(() => {
    whois.info(host1)
    .then(data => console.log(`${host1} info:\n`, JSON.stringify(data, null, 4)))
    .catch(err => console.log(err));

    whois.info(host2)
    .then(data => console.log(`${host2} info:\n`, JSON.stringify(data, null, 4)))
    .catch(err => console.log(err));
})
.catch(err => console.log(err));

@license MIT @version 2.0.10 @author Alexander Russkiy [email protected]