Standalone IP to ISO2 Country Code
Based on db-ip.com freely available database, the aim of this program is to return a 2 chars Country Code given a generic ip.
The main reason this software exists is to quickly understand if an IP comes from a European country and, as such, is subject to the Cookie's Law absurdity.
The list of known IPv4 and IPv6 is stored entirely in RAM in order to grant zero dependencies and overall good performance if used as module.
varipcc =ip = '126.96.36.199';// using an EU ipipcc; // "UK"ipcc; // true// using a non-EU ipip = '188.8.131.52';ipcc; // "US"ipcc; // false
The API is pretty basic, consisting in
Please note latter 2 methods are very simple and are not suitable to validate entirely IP v4 or v6 ddresses.
Used as stand alone, the script will actually use a lot of CPU in order to properly parse static Arrays defined in it.
However, this is the way you can use it:
$ # if the following command fails, try with sudo$ npm install -g ipcc$$ # test some IP (v4 or v6)$ ipcc 184.108.40.206 # UK (EU)$ ipcc 220.127.116.11 # US
Please note that only EU countries will contain the
In case you need this data as SQLite file, you can clone this repository locally and perform following operations:
$ git clone https://github.com/WebReflection/ipcc.git$ cd ipcc$ npm install$ node generate.js
It will also generate a fresh new copy of
In order to query the database, you can use src/utils.js file
which together with
dblite should give you the ability to query as such:
// copy utils.js functions on topvardblite =db =// retrieve the IP the way you wantip = '18.104.22.168'table = ? 'ipv4' : 'ipv6'norm = ? :;db;
All rights reserved to ip-db.com for their data. Mit Style License for the code I've written.