2.0.8 • Published 8 years ago

hostname-is-private v2.0.8

Weekly downloads
30
License
MIT
Repository
github
Last release
8 years ago

hostname-is-private Build Status

Check whether or not an hostname refers to a private IP

Setup

npm install hostname-is-private

Usage

isPrivate(hostname: {String}, f: (err : {Error,Null}, isPrivate: {Boolean}))

var isPrivate = require('hostname-is-private').isPrivate;

isPrivate('127.0.0.1.xip.io', function(err, isPrivate){
    console.log(err === null, isPrivate == true);
});

isPrivate('localhost', function(err, isPrivate){
    console.log(err === null, isPrivate === true);
});

isPrivate('google.com', function(err, isPrivate){
    console.log(err === null, isPrivate === false);
});

isPrivateIncludingPublicIp(hostname: {String}, f: (err : {Error,Null}, isPrivateIncludingPublicIp: {Boolean}))

var isPrivateIncludingPublicIp = require('hostname-is-private').isPrivateIncludingPublicIp;

isPrivateIncludingPublicIp('YOUR-PUBLIC-IP.xip.io', function(err, isPrivate){
    console.log(err === null, isPrivate == true);
});

isPrivate('localhost', function(err, isPrivate){
    console.log(err === null, isPrivate === true);
});

isPrivate('google.com', function(err, isPrivate){
    console.log(err === null, isPrivate === false);
});

How it works

It uses dns.lookup underneath and ip.isPrivate to check if the resolved IP is private (or not).

Changelog

2.0.8

8 years ago

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.0

9 years ago