ip-info

0.0.1 • Public • Published

ip-info

Build Status Dependency Status devDependency Status

Get IP information include country, province, city and operator.

Getting Started

Install with this command:

npm i ip-info --save

Or maybe you like yarn:

yarn add ip-info

How to use

You should import this module first:

var ip = require('ip-info');

The ip above is a function which accepts a config object and returns a promise. The only thing you should do is passing a config object and have fun!

Config

ipReg {String} [OPTION]

Default: ^(?:\d{1,3}\.){3}\d{1,3}$

This string will be used as RegExp to test every ip.

ip {String | Array}

The target ip or ip list. You must supply one of ip or input.

input {String}

The file path for target ip list. You must supply one of ip or input.

output {String} [OPTION]

The file path for output.

cwd {String} [OPTION]

Default: the directory of file which use this module

This path will be used to join with input and output path.

format {String} [OPTION]

Default: json

The format for input and output file. Only support json and yaml now. Welcome PR >.<

encoding {String} [OPTION]

Default: utf8

The encoding for input and output file.

service {String} [OPTION]

Default: ipip.net

The ip search service. Only support ipip.net now. Welcome PR >.<

interval {Number} [OPTION]

Default: 300

The time interval between each request to prevent ban.

Sample

Basic

var ip = require('../index.js');
 
ip({
    ip: '8.8.8.8'
}).then(res => {
    // deal with result
}).catch(err => {
    // deal with error
});

More config

var ip = require('../index.js');
 
ip({
    cwd: 'relative/path/',
    input: 'path/to/input.yml',
    format: 'yaml',
    output: 'path/to/output.json',
    interval: '500'
});

Test

npm test

TODO

  • Support service account
  • Add more service such as ipinfo.io, ip.taobao.com

History

  • 0.0.1
    • init

Readme

Keywords

Package Sidebar

Install

npm i ip-info

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • poppinl