https://github.com/ssbc/non-private-ip
https://github.com/ssbc/non-private-ip
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/ssbc/non-private-ip
- Owner: ssbc
- License: mit
- Created: 2014-12-26T06:56:38.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T04:17:39.000Z (over 3 years ago)
- Last Synced: 2025-06-11T16:36:01.034Z (about 1 year ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# non-private-ip
Picks the first reasonable looking IP address from network interfaces.
This should _just work_ when running on a VPS, but also provides `private` APIs
so that when running in LAN you get the first reasonable looking LAN IP address.
More info: http://en.wikipedia.org/wiki/Private_network
Your laptop probably does not have a non-local IP address, but your VPS server
probably does. This just returns the first address, which will probably be IPv4.
This module is based on the ["ip" module](https://www.npmjs.com/package/ip).
## API
The main export is a function `nonPrivateIP(interfaces, filter, details)` where:
- `interfaces` is either `null` or a mock of `os.networkInterfaces()`, typically
**this should be `null`**
- `filter` is a **function** of the shape `(address, details) => boolean` where
`address` is the IP address as a string, and `details` is the whole object
with additional fields, e.g. `address`, `netmask`, `family`, `mac`, `cidr`,
etc
- `details` is a boolean that controls whether you want the return of the
function to be just the IP address as a string (`false`, this is the
**default**) or the whole object with additional fields (`true`)
```js
// On a VPS:
const nonPrivateIP = require('non-private-ip')
nonPrivateIP() // 80.78.25.153
```
```js
// In a LAN:
const nonPrivateIP = require('non-private-ip')
nonPrivateIP.private() // 192.168.0.101
```
## License
MIT