npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-ip-location-lite

v1.0.1

Published

A Node-Red node to determine (locally) the geographic location of an IP address.

Downloads

30

Readme

node-red-contrib-ip-location-lite

Node-Red node to determine (locally) the geographic location of an IP address

Install

Run the following npm command in your Node-RED user directory (typically ~/.node-red):

npm install node-red-contrib-ip-location-lite

Support my Node-RED developments

Please buy my wife a coffee to keep her happy, while I am busy developing Node-RED stuff for you ...

Node usage

This node determines offline the geographic location (country, region and city) of a specified IP address, based on a local set of data files available from Maxmind.

This node is a lite version, because the original (fully featured) Maxmind geoip npm package requires libgeoip to be installed on your system. To avoid installation issues, this node uses the full Javascript geoip-lite npm package (which has limited functionality).

Remarks:

  • Both IPv4 and IPv6 addresses are supported, however since the GeoLite IPv6 database does not currently contain any city or region information, city, region and postal code lookups are only supported for IPv4.
  • The geoip-lite package stores all data in RAM in order to be fast.

Get IP address location

The following flow injects an input message, containing the IP address in msg.payload. The output message will contain the geo location in msg.location:

Example flow

[{"id":"b5b96025f6e97f0c","type":"ip-location-lite","z":"f3483c9d.032fa","name":"","inputField":"payload","outputField":"location","x":590,"y":1260,"wires":[["29f2be0278ae17fc"]]},{"id":"cf6e2e892be1a211","type":"inject","z":"f3483c9d.032fa","name":"Inject ipV4 address","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"207.97.227.239","payloadType":"str","x":330,"y":1260,"wires":[["b5b96025f6e97f0c"]]},{"id":"29f2be0278ae17fc","type":"debug","z":"f3483c9d.032fa","name":"Geo IP location","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":780,"y":1260,"wires":[]},{"id":"b0e1f953c2f4195e","type":"inject","z":"f3483c9d.032fa","name":"Inject local ip address","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"192.168.123.255","payloadType":"str","x":340,"y":1340,"wires":[["b5b96025f6e97f0c"]]},{"id":"23c0d691f38442bf","type":"inject","z":"f3483c9d.032fa","name":"Inject ipV6 address","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2001:4860:b002::68","payloadType":"str","x":330,"y":1300,"wires":[["b5b96025f6e97f0c"]]},{"id":"68706191f7ec8bb2","type":"inject","z":"f3483c9d.032fa","name":"Inject invalid ip address","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"blabla","payloadType":"str","x":340,"y":1380,"wires":[["b5b96025f6e97f0c"]]}]

The advantage of sending the geo location result in another msg field, is that the orginal IP address will still be available in the output message. Which means the output message contains all data, both input and output:

JSON result

Update local database

:warning: CAUTION:

  • The 'update' command will download about 110 Mb data files to your filesystem.
  • The 'update' command will take about 35 minutes on a Raspberry Pi 3.

When this node is being installed, it already contains a set of data files. So you can get started immediately. However it is advised to update your local geo database from time to time, using following flow:

Update db flow

[{"id":"ef6a184e.c7e998","type":"ip-location-lite","z":"11289790.c89848","name":"","inputField":"payload","outputField":"payload","x":450,"y":820,"wires":[[]]},{"id":"862e5358.84171","type":"inject","z":"11289790.c89848","name":"Update database","topic":"","payload":"update","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":820,"wires":[["ef6a184e.c7e998"]]}]

The following steps need to be executed:

  1. Create a free Maxmind account here.

  2. Generate a license key on your Maxmind account page.

  3. Download the new data files, by injecting an input message with msg.payload = "update".

  4. The node status will change to "updating ...", where the dots will be animated to visualize the database progress.

  5. As soon as the database is updated, the node status will change to "updated".

  6. At the end, the data files will be up-to-date:

    data files

Remark: when the database is already up-to-date, then the status will change very fast from "updating" to "updated".

Node configuration

License key

A license key is only required to download data updates from Maxmind. See above how to use it.

Input field

The name of the field in the input message, where the IP address needs to be specified. By default the input field will be msg.payload.

Output field

The name of the field in the output message, where the geographic location information will be stored. By default the output field will also be msg.payload. But it might be advised to use another msg field, if you don't want to overwrite the original IP address from the input message.