【问题标题】:Is there a node.js module that can determine Geolocation of an IP? [closed]是否有可以确定 IP 地理位置的 node.js 模块? [关闭]
【发布时间】:2011-10-17 03:38:11
【问题描述】:

给个IP,有没有node.js模块可以判断它在哪个城市和哪个州?

【问题讨论】:

  • 投反对票“显示没有研究工作”因为网络搜索“node.js geoip”或“node.js geolocation”会立即找到相关模块。
  • 我现在google的时候会出现这个问题...

标签: javascript node.js geolocation ip geoip


【解决方案1】:

我发现node-maxmind 是功能最完整且易于使用的模块。你需要从maxminddownload page下载文件,然后就可以这样使用了:

maxmind = require 'maxmind'
maxmind.init('GeoLiteCity.dat')
maxmind.getLocation('67.188.232.131')

{ countryCode: 'US',
  countryName: 'United States',
  region: 'CA',
  city: 'Mountain View',
  postalCode: '94043',
  latitude: 37.41919999999999,
  longitude: -122.0574,
  dmaCode: 0,
  areaCode: 0,
  metroCode: 0,
  regionName: 'California' }

使用通常需要您安装地理定位数据库并定期更新它的模块的替代方法是使用地理定位 API。我自己的服务之一是http://ipinfo.io。这是一个使用出色的请求模块调用它的示例:

request = require 'request'
request.get('http://ipinfo.io/67.188.232.131', {json: true}, (e, r) -> console.log r.body)

{ ip: '67.188.232.131',
  hostname: 'c-67-188-232-131.hsd1.ca.comcast.net',
  city: 'Mountain View',
  region: 'California',
  country: 'US',
  loc: '37.4192,-122.0574',
  org: 'AS7922 Comcast Cable Communications, Inc.',
  postal: '94043' }

更多详情请见http://ipinfo.io/developers

【讨论】:

  • 我试过了,但切换到node-maxmind-db,因为它同时具有同步异步API,同样的方法调用支持IPv4 IPv6 ,并且它适用于较新的 MaxMind 格式。
【解决方案2】:

你看过node.js modules page吗?

它列出了GeoIPnode-geoipnode-maxmindnode-maxmind-native

【讨论】:

猜你喜欢
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
  • 2013-11-09
  • 2012-06-23
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 2011-01-11
相关资源
最近更新 更多