GithubHelp home page GithubHelp logo

yourtion / node-ip2region Goto Github PK

View Code? Open in Web Editor NEW
115.0 3.0 13.0 26.33 MB

IP/IPv6 to region on Node.js (IP/IPv6 地址到区域运营商)

Home Page: https://www.npmjs.com/package/ip2region

License: MIT License

JavaScript 0.34% Shell 2.76% TypeScript 96.90%
ip ipaddress-to-address ip-address ip-location ip-region ip-lookup ip-search ip-geo node-ip2region ipv6

node-ip2region's Introduction

NPM version build status Test coverage David deps node version npm download npm license

node-ip2region

IP 地址到区域运营商 IP(支持 IPv6) to region on Node.js

安装使用使用

$ npm install ip2region --save
// const IP2Region = require('ip2region').default;
import IP2Region from "ip2region";
const query = new IP2Region();
const res = query.search('120.24.78.68');
console.log(res);
> { country: '**', province: '广东省', city: '深圳市', isp: '阿里云' }
const res2 = query.search('240e:47d:c20:1627:30a3:ba0d:a5e6:ec19');
console.log(res2);
> { country: "**", province: "广东省", city: "", isp: "**电信" }

配置

  • ipv4db: ipv4 数据库地址
  • ipv6db: ipv6 数据库地址
  • disableIpv6: 关闭 ipv6 查询功能(减少内存占用)
import IP2Region from "ip2region";
const query = new IP2Region({
  ipv4db: "/tmp/db4.db",
  ipv6db: "/tmp/db6.db",
  disableIpv6: true,
});

node-ip2region's People

Contributors

greenkeeper[bot] avatar yourtion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-ip2region's Issues

An in-range update of eslint is breaking the build 🚨

Version 4.15.0 of eslint was just published.

Branch Build failing 🚨
Dependency eslint
Current Version 4.14.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • coverage/coveralls Coverage pending from Coveralls.io Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v4.15.0
  • 6ab04b5 New: Add context.report({ messageId }) (fixes #6740) (#9165) (Jed Fox)
  • fc7f404 Docs: add url to each of the rules (refs #6582) (#9788) (Patrick McElhaney)
  • fc44da9 Docs: fix sort-imports rule block language (#9805) (ferhat elmas)
  • 65f0176 New: CLIEngine#getRules() (refs #6582) (#9782) (Patrick McElhaney)
  • c64195f Update: More detailed assert message for rule-tester (#9769) (Weijia Wang)
  • 9fcfabf Fix: no-extra-parens false positive (fixes: #9755) (#9795) (Erin)
  • 61e5fa0 Docs: Add table of contents to Node.js API docs (#9785) (Patrick McElhaney)
  • 4c87f42 Fix: incorrect error messages of no-unused-vars (fixes #9774) (#9791) (akouryy)
  • bbabf34 Update: add ignoreComments option to indent rule (fixes #9018) (#9752) (Kevin Partington)
  • db431cb Docs: HTTP -> HTTPS (fixes #9768) (#9768) (Ronald Eddy Jr)
  • cbf0fb9 Docs: describe how to feature-detect scopeManager/visitorKeys support (#9764) (Teddy Katz)
  • f7dcb70 Docs: Add note about "patch release pending" label to maintainer guide (#9763) (Teddy Katz)
Commits

The new version differs by 14 commits.

  • e14ceb0 4.15.0
  • 2dfc3bd Build: changelog update for 4.15.0
  • 6ab04b5 New: Add context.report({ messageId }) (fixes #6740) (#9165)
  • fc7f404 Docs: add url to each of the rules (refs #6582) (#9788)
  • fc44da9 Docs: fix sort-imports rule block language (#9805)
  • 65f0176 New: CLIEngine#getRules() (refs #6582) (#9782)
  • c64195f Update: More detailed assert message for rule-tester (#9769)
  • 9fcfabf Fix: no-extra-parens false positive (fixes: #9755) (#9795)
  • 61e5fa0 Docs: Add table of contents to Node.js API docs (#9785)
  • 4c87f42 Fix: incorrect error messages of no-unused-vars (fixes #9774) (#9791)
  • bbabf34 Update: add ignoreComments option to indent rule (fixes #9018) (#9752)
  • db431cb Docs: HTTP -> HTTPS (fixes #9768) (#9768)
  • cbf0fb9 Docs: describe how to feature-detect scopeManager/visitorKeys support (#9764)
  • f7dcb70 Docs: Add note about "patch release pending" label to maintainer guide (#9763)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

哥们 最近我也在研究这个ip2region库,有些问题讨论下

这个ip2region 库的这些转化是怎么进行的?
数据怎么挂钩的,只知道ip转化乘以不同的数字转化成一个相对有意义的数字,然后在数据库中进行挂钩,还有库中很多的偏移都是什么意思。。。一脸懵逼。。
这涉及到哪些基础知识,还望指点。
敬请赐教!~!谢谢!,在此打扰了。

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

ipv6现在还不支持吧?

我做了测试,发现ipv6的地址会被解析到印度孟买。

const IP2Region = require('ip2region');
const query = new IP2Region();
const res = query.search('2409:8946:2d51:1569:dfdb:6dcf:dd39:5d9a');

console.log(res);

输出结果是

{
  id: 0,
  country: '印度',
  region: '0',
  province: '马哈拉施特拉',
  city: '孟买',
  isp: '印度电信'
}

node ES6语法引入无法正常使用,ES5语法才可以使用

使用作者提供的ES6 import导入无法正常使用,报错为:

TypeError: IP2Region is not a constructor
    at file:///C:/Users/17218/Desktop/getip/app.js:17:23
    at Layer.handle [as handle_request] (C:\Users\17218\Desktop\getip\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\17218\Desktop\getip\node_modules\express\lib\router\route.js:144:13)
    at Route.dispatch (C:\Users\17218\Desktop\getip\node_modules\express\lib\router\route.js:114:3)
    at Layer.handle [as handle_request] (C:\Users\17218\Desktop\getip\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\17218\Desktop\getip\node_modules\express\lib\router\index.js:284:15
    at Function.process_params (C:\Users\17218\Desktop\getip\node_modules\express\lib\router\index.js:346:12)
    at next (C:\Users\17218\Desktop\getip\node_modules\express\lib\router\index.js:280:10)
    at expressInit (C:\Users\17218\Desktop\getip\node_modules\express\lib\middleware\init.js:40:5)
    at Layer.handle [as handle_request] (C:\Users\17218\Desktop\getip\node_modules\express\lib\router\layer.js:95:5)

代码是这样的

import express from 'express';
import IP2Region from 'ip2region';

const app = express();

app.get('/', (req, res) => {
    let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
    if (ip.includes('::ffff:')){
        ip = ip.split('::ffff:')[1];
    }
    const ip2Region = new IP2Region();
    const ipAdress = ip2Region.search(ip)
    res.send({ip,ipAdress});
});

app.listen(3000, () => {
    console.log('http://localhost:3000');
})

egg.js 使用ip2region 报错

/usr/blog/api/node_modules/ip2region/dist/lib/ipv6.js:199
[egg-scripts] if (ip6 === 0x1n) {
[egg-scripts] ^^^
[egg-scripts]
[egg-scripts] SyntaxError: Invalid or unexpected token
[egg-scripts] at createScript (vm.js:80:10)
[egg-scripts] at Object.runInThisContext (vm.js:139:10)
[egg-scripts] at Module._compile (module.js:617:28)
[egg-scripts] at Object.Module._extensions..js (module.js:664:10)
[egg-scripts] at Module.load (module.js:566:32)
[egg-scripts] at tryModuleLoad (module.js:506:12)
[egg-scripts] at Function.Module._load (module.js:498:3)
[egg-scripts] at Module.require (module.js:597:17)
[egg-scripts] at require (internal/module.js:11:18)
[egg-scripts] at Object. (/usr/blog/api/node_modules/ip2region/dist/lib/index.js:7:32)
[egg-scripts] 2021-01-13 11:58:29,357 ERROR 31607 nodejs.AppWorkerDiedError: [master] app_worker#1:31623 died (code: 1, signal: null, suicide: false, state: dead), current workers: []
[egg-scripts] at Master.onAppExit (/usr/blog/api/node_modules/egg-cluster/lib/master.js:510:21)
[egg-scripts] at emitOne (events.js:116:13)
[egg-scripts] at Master.emit (events.js:211:7)
[egg-scripts] at Messenger.sendToMaster (/usr/blog/api/node_modules/egg-cluster/lib/utils/messenger.js:137:17)
[egg-scripts] at Messenger.send (/usr/blog/api/node_modules/egg-cluster/lib/utils/messenger.js:102:12)
[egg-scripts] at EventEmitter.cluster.on (/usr/blog/api/node_modules/egg-cluster/lib/master.js:353:22)
[egg-scripts] at emitThree (events.js:141:20)
[egg-scripts] at EventEmitter.emit (events.js:217:7)
[egg-scripts] at ChildProcess.worker.process.once (internal/cluster/master.js:191:13)
[egg-scripts] at Object.onceWrapper (events.js:317:30)
[egg-scripts] name: "AppWorkerDiedError"
[egg-scripts] pid: 31607
[egg-scripts] hostname: iz2zeinnzibsruhaliwavbz
[egg-scripts]
[egg-scripts] 2021-01-13 11:58:29,357 ERROR 31607 [master] app_worker#1:31623 start fail, exiting with code:1
[egg-scripts] 2021-01-13 11:58:29,358 ERROR 31607 [master] exit with code:1
[egg-scripts] 2021-01-13 11:58:29,364 ERROR 31613 [agent_worker] receive disconnect event on child_process fork mode, exiting with code:110
[egg-scripts] 2021-01-13 11:58:29,367 ERROR 31613 [agent_worker] exit with code:110
[egg-scripts]

An in-range update of coveralls is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye 👋 and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The devDependency coveralls was updated from 3.0.9 to 3.0.10.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

coveralls is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for CodeFresh support, Maintenance

Added:

  • CodeFresh support (@suda)

Improved:

Updated:

Commits

The new version differs by 6 commits.

  • 2ea7be3 bump version
  • 5e976c5 Only coverage report on test success, fixes #230
  • 3d83b4f Set service_name and/or repo_token from .coveralls.yml regardless of if $COVERALLS_REPO_TOKEN is set (#272)
  • 710c504 Add Codefresh support
  • 8c4ba99 CI: switch to actions/checkout@v2
  • eb1a3c9 278 Upgrades minimist dependency to 1.2.5

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.