3.0.0 • Published 7 years ago

ipip-ex v3.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

node-ipip Build Status Coverage Status npm version

中文文档

English Version README is out of date

A Node.js module to query geolocation information for an IP or domain, based on database by ipip.net.

Getting Started

Install the module:

npm install ipip

Database is provided by ipip.net. If unzip command is avaliable, the database will be automatically downloaded during installation. Otherwise, you'll have to manually extract the database, if you are using Windows.

Documentation

Load database

Since v2.0, the module itself is a loader function. Just pass the path to load a paid database file, or simply leaving it blank to use default free data.

var ip = require('ipip')();

// lookup an ip
console.log(ip('202.195.161.30'));

Use an alternative database file path for paid data:

var ip = require('ipip')('/path/to/your/17monip.datx');

NOTE Loading database is a synchronized function.

Query

ip(ip , format)

ip

IP address that you want to query. e.g. 8.8.8.8

format

Format of the information, shoule be array or dict.

By default it will use the free version.

When set to dict you'll get an object that consists of four keys: country, province, city. e.g.:

{
  country: '中国',
  province: '江苏',
  city: '镇江'
}

Otherwise, it returns an array as following format: ['country', 'province', 'city'].

For paid users (data file should have the "datx" extension), there are more fields: ['isp', 'latitude', 'longitude', 'timezone', 'timezone2', 'governcode']

Command line util

If installed globally, you can use ipip command in your shell to query IP information.

➜  ~ ipip 8.8.8.8 202.195.161.30
Information for 8.8.8.8:
country: GOOGLE
province: GOOGLE
city: N/A

Information for 202.195.161.30:
country: 中国
province: 江苏
city: 镇江

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Use make to run unit test.

License

(C) Copyright 2016 ChiChou. Licensed under the MIT license.