Socket
Socket
Sign inDemoInstall

ip-monitor

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ip-monitor - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

.eslintrc.json

30

examples/basic.js
'use strict';
var ipMon = require('../index');
const IpMonitor = require('../index');
var watcher = ipMon.createWatcher();
const ipMonitor = new IpMonitor();
watcher.on('IP:change', function (prevIP, newIP) {
console.log('Prev IP: %s, New IP: %s', prevIP, newIP);
ipMonitor.on('change', (prevIp, newIp) => {
console.log(`IP changed from ${prevIp} to ${newIp}`);
});
/*
Generic error event
*/
watcher.on('error', function (error) {
throw error;
});
/*
Seperate event for ip error handling.
It will fire when the connection has been lost, e.g your router is restarting,
thats why you may want to handle it differently than other errors.
*/
watcher.on('IP:error', function (error) {
console.log('Cant get external IP: ' + error);
ipMonitor.on('error', (error) => {
console.error(error);
});
watcher.on('IP:success', function (IP) {
console.log('Got IP: %s', IP);
});
watcher.start();
ipMonitor.start();
'use strict';
var ipMon = require('../index');
const IpMonitor = require('../index');
var watcher = ipMon.createWatcher({
polling: 10000,
externalIP: {
const ipMonitor = new IpMonitor({
pollingInterval: 36000,
verbose: true,
externalIp: {
timeout: 1000,
getIP: 'parallel',
services: ['http://ifconfig.co/x-real-ip', 'http://icanhazip.com/'],
replace: true
replace: true,
verbose: true
}
});
watcher.on('IP:change', function (prevIP, newIP) {
console.log('Prev IP: %s, New IP: %s', prevIP, newIP);
ipMonitor.on('change', (prevIp, newIp) => {
console.log(`IP changed from ${prevIp} to ${newIp}`);
});
/*
Generic error event
*/
watcher.on('error', function (error) {
throw error;
});
/*
Seperate event for ip error handling.
It will fire when the connection has been lost, e.g your router is restarting,
thats why you may want to handle it differently than other errors.
*/
watcher.on('IP:error', function (error) {
console.log('Cant get external IP: ' + error);
ipMonitor.on('error', (error) => {
console.error(error);
});
watcher.on('IP:success', function (IP) {
console.log('Got IP: %s', IP);
});
watcher.start();
ipMonitor.start();
'use strict';
var Watcher = require('./lib/watcher').Watcher;
var utils = require('./lib/utils');
var extIP = require('external-ip');
module.exports.createWatcher = function (extConfig) {
extConfig = extConfig || {};
var isValid = utils.validateConfig(extConfig);
if(isValid.errors.length) {
throw new Error(isValid.errors);
}
var defaultConfig = {
polling: 20000,
externalIP: {}
};
var config = utils.mergeConfig(extConfig, defaultConfig);
var getIP = extIP(config.externalIP);
return new Watcher(getIP, config);
};
module.exports = require('./lib/Watcher');
{
"name": "ip-monitor",
"version": "0.1.2",
"version": "1.0.0",
"description": "A node.js library to monitor your external ip",

@@ -28,9 +28,8 @@ "main": "index.js",

"dependencies": {
"external-ip": "^0.2.0",
"revalidator": "^0.2.0"
"external-ip": "^2.0.3"
},
"devDependencies": {
"chai": "^1.9.1",
"mocha": "^1.21.4"
"chai": "^4.1.2",
"mocha": "^5.0.4"
}
}

@@ -1,2 +0,5 @@

#ip-monitor [![Build Status](https://travis-ci.org/J-Chaniotis/ip-monitor.svg)](https://travis-ci.org/J-Chaniotis/ip-monitor) [![Dependency Status](https://david-dm.org/j-Chaniotis/ip-monitor.svg)](https://david-dm.org/j-Chaniotis/ip-monitor)
# ip-monitor
[![Build Status](https://travis-ci.org/J-Chaniotis/ip-monitor.svg?branch=master)](https://travis-ci.org/J-Chaniotis/ip-monitor)
[![dependencies Status](https://david-dm.org/j-Chaniotis/ip-monitor/status.svg)](https://david-dm.org/j-Chaniotis/ip-monitor)
[![npm version](https://badge.fury.io/js/ip-monitor.svg)](https://badge.fury.io/js/ip-monitor)

@@ -8,3 +11,3 @@

using [npm](https://www.npmjs.org/package/ip-monitor): `npm install ip-monitor`
`npm install ip-monitor`

@@ -14,34 +17,16 @@ ## Usage

```javascript
'use strict';
var ipMon = require('ip-monitor');
const IpMonitor = require('ip-monitor');
const ipMonitor = new IpMonitor();
var watcher = ipMon.createWatcher();
watcher.on('IP:change', function (prevIP, newIP) {
console.log('Prev IP: %s, New IP: %s', prevIP, newIP);
ipMonitor.on('change', (prevIp, newIp) => {
console.log(`IP changed from ${prevIp} to ${newIp}`);
});
/*
Generic error event
*/
watcher.on('error', function (error) {
throw error;
ipMonitor.on('error', (error) => {
console.error(error);
});
/*
Seperate event for ip error handling.
It will fire when the connection has been lost, e.g your router is restarting,
thats why you may want to handle it differently than regular errors.
*/
watcher.on('IP:error', function (error) {
console.log('Cant get external IP: ' + error);
});
ipMonitor.start();
watcher.on('IP:success', function (IP) {
console.log('Got IP: %s', IP);
});
watcher.start();
```

@@ -51,30 +36,42 @@

```javascript
var watcher = ipMon.createWatcher({
polling: 10000,
externalIP: {
const IpMonitor = require('ip-monitor');
const ipMonitor = new IpMonitor({
pollingInterval: 36000,
verbose: true,
externalIp: {
timeout: 1000,
getIP: 'parallel',
services: ['http://ifconfig.co/x-real-ip', 'http://icanhazip.com/'],
replace: true
replace: true,
verbose: true
}
});
ipMonitor.on('change', (prevIp, newIp) => {
console.log(`IP changed from ${prevIp} to ${newIp}`);
});
ipMonitor.on('error', (error) => {
console.error(error);
});
ipMonitor.start();
```
##API
### Configuration
`ipmon.createWatcher([config])` accepts a configuration object with the following optional properties:
* <b>`polling: <Integer>`:</b> how often to poll for ip changes, default 20000ms
* <b>`externalIP: <Object>`:</b> configuration passed directly to [`external-ip`](https://github.com/J-Chaniotis/external-ip/blob/master/README.md)
## Configuration
`new IpMonitor([config])` accepts a configuration object with the following optional properties:
* <b>`pollingInterval: <Integer>`:</b> how often to poll for ip changes, default 1 day
* <b>`externalIp: <Object>`:</b> configuration passed directly to [`external-ip`](https://github.com/J-Chaniotis/external-ip/blob/master/README.md)
### Methods
## Methods
* <b>`.start()`:</b> start watching
* <b>`.stop()`:</b> stop watching
* <b>`.poll()`:</b> poll for ip manually
* <b>`.isWatching()`:</b> check if ip-monitor has started
### Events
* <b>`IP:success` :</b> fired every time `.poll()` yields an ip
* <b>`IP:error`:</b> fired when `.poll()` encounters an error, usually if the connection is down
* <b>`IP:change`:</b> fired when the external ip has changed. it will also fire the first time `.start()` or `.poll()` are invoked.
## Events
* <b>`change`:</b> fired when the external ip has changed. it will also fire the first time `.start()` or `.poll()` are invoked.
* <b>`error`:</b> typical error handling here
## Test
Change your working directory to the project's root, `npm install` to get the development dependencies and then `npm test`

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc