ip-monitor
A node.js library to monitor your external ip for changes
Installation
npm install ip-monitor
Usage
basic
const IpMonitor = require('ip-monitor');
const ipMonitor = new IpMonitor();
ipMonitor.on('change', (prevIp, newIp) => {
console.log(`IP changed from ${prevIp} to ${newIp}`);
});
ipMonitor.on('error', (error) => {
console.error(error);
});
ipMonitor.start();
with custom configuration
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,
verbose: true
}
});
ipMonitor.on('change', (prevIp, newIp) => {
console.log(`IP changed from ${prevIp} to ${newIp}`);
});
ipMonitor.on('error', (error) => {
console.error(error);
});
ipMonitor.start();
Configuration
new IpMonitor([config])
accepts a configuration object with the following optional properties:
pollingInterval: <Integer>
: how often to poll for ip changes, default 1 dayexternalIp: <Object>
: configuration passed directly to external-ip
Methods
.start()
: start watching.stop()
: stop watching.poll()
: poll for ip manually
Events
change
: fired when the external ip has changed. it will also fire the first time .start()
or .poll()
are invoked.error
: 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