# hostname-is-private

> Check whether or not an hostname refer to a private IP

Latest version **2.0.8** (published 2016-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install hostname-is-private
pnpm add hostname-is-private
yarn add hostname-is-private
bun add hostname-is-private
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.8 |
| Published | 2016-04-27 |
| First published | 2015-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Francois-Guillaume Ribreau |
| Maintainers | fgribreau |
| Keywords | hostname, host, ip, private, network |

## Links

- npm: https://www.npmjs.com/package/hostname-is-private
- Repository: https://github.com/FGRibreau/hostname-is-private
- Issues: https://github.com/FGRibreau/hostname-is-private/issues
- npm.io page: https://npm.io/package/hostname-is-private

## Dependencies (4)

- [ip](https://npm.io/package/ip.md) 1.x.x
- [lodash](https://npm.io/package/lodash.md) ^4.0.1
- [public-ip](https://npm.io/package/public-ip.md) 1.x.x
- [isipaddress](https://npm.io/package/isipaddress.md) 0.0.2

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 2.0.8 (latest) — 2016-04-27
- 2.0.7 — 2016-04-27
- 2.0.6 — 2016-01-26
- 2.0.5 — 2015-09-07
- 2.0.4 — 2015-07-04
- 2.0.3 — 2015-04-05
- 2.0.2 — 2015-04-05
- 2.0.1 — 2015-04-05
- 2.0.0 — 2015-04-05
- 1.0.0 — 2015-04-04

## README

# hostname-is-private [![Build Status](https://drone.io/github.com/FGRibreau/hostname-is-private/status.png)](https://drone.io/github.com/FGRibreau/hostname-is-private/latest)


> Check whether or not an hostname refers to a private IP

## Setup

```shell
npm install hostname-is-private
```

<p align="center">
<a target="_blank" href="https://play.spotify.com/track/5vrwlyErg2E1bnDVLH5GhH"><img style="width:100%" src="https://cloud.githubusercontent.com/assets/138050/6993821/c4e023a6-db01-11e4-85aa-840078efe431.gif"></a>
</p>

## Usage

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

```javascript
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}))`

```javascript
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](https://nodejs.org/api/all.html#all_dns_resolve_hostname_rrtype_callback) underneath and [ip.isPrivate](https://github.com/indutny/node-ip#ip) to check if the resolved IP is private (or not).

## [Changelog](/CHANGELOG.md)

---
_Source: https://npm.io/package/hostname-is-private · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
