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

A node.js library to monitor your external ip


Version published
Weekly downloads
5
decreased by-44.44%
Maintainers
1
Weekly downloads
 
Created
Source

#ip-monitor Build Status Dependency Status

A node.js library to monitor your external ip for changes

Installation

using npm: npm install ip-monitor

Usage

basic

'use strict';
var ipMon = require('ip-monitor');

var watcher = ipMon.createWatcher();

watcher.on('IP:change', function (prevIP, newIP) {
    console.log('Prev IP: %s, New IP: %s', prevIP, 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 regular errors.
*/
watcher.on('IP:error', function (error) {
    console.log('Cant get external IP: ' + error);
});

watcher.on('IP:success', function (IP) {
    console.log('Got IP: %s', IP);
});


watcher.start();

with custom configuration

var watcher = ipMon.createWatcher({
    polling: 10000,
    externalIP: {
        timeout: 1000,
        getIP: 'parallel',
        services: ['http://ifconfig.co/x-real-ip', 'http://icanhazip.com/'],
        replace: true
    }
});

##API

Configuration

ipmon.createWatcher([config]) accepts a configuration object with the following optional properties:

  • polling: <Integer>: how often to poll for ip changes, default 20000ms
  • externalIP: <Object>: configuration passed directly to external-ip

Methods

  • .start(): start watching
  • .stop(): stop watching
  • .poll(): poll for ip manually
  • .isWatching(): check if ip-monitor has started

Events

  • IP:success : fired every time .poll() yields an ip
  • IP:error: fired when .poll() encounters an error, usually if the connection is down
  • IP: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

Keywords

FAQs

Package last updated on 27 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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