node-red-contrib-ip-location-lite 1.0.1

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

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

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 ...

Buy my wife a coffee

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.

Node Info

Version: 1.0.1
Updated 3 years, 8 months ago
License: Apache-2.0
Rating: not yet rated

Categories

Actions

Rate:

Downloads

11 in the last week

Nodes

  • ip-location-lite

Keywords

  • node-red
  • ip
  • address
  • geo
  • location

Maintainers