ipfs-geoip
Library for ipfs geoip lookups
Last updated 20 days ago by lidel .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ipfs-geoip 
SYNC missed versions from official npm registry.

IPFS GeoIP

standard-readme compliant Dependency Status Travis CI Coverage Status

geoip lookup over ipfs

Install

NPM

npm install --save ipfs-geoip

CDN

Instead of a local installation (and browserification) you may request a remote copy from jsDelivr:

<!-- loading the minified version using jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/ipfs-geoip@5.0.1/dist/index.min.js"></script>

When using prebuilt bundle from CDN, ipfs-geoip will be exposed under window.IpfsGeoip

Usage

const geoip = require('ipfs-geoip')
const ipfs = require('ipfs-http-client')()

const exampleIp = '89.114.95.36'

try {
  const result = await geoip.lookup(ipfs, exampleIp)
  console.log('Result: ', result)
} catch (err) {
  console.log('Error: ' + err)
}

try {
  const result = await geoip.lookupPretty(ipfs, '/ip4/' + exampleIp)
  console.log('Pretty result: %s', result.formatted)
} catch (err) {
  console.log('Error: ' + err)
}

API

lookup(ipfs, ip)

Returns a promise that resolves to an object of the form

{
  "country_code": "US",
  "country_name": "USA",
  "region_code": "CA",
  "city": "Mountain View",
  "postal_code": "94040",
  "latitude": 37.3860,
  "longitude": -122.0838,
  "metro_code": "807",
  "area_code": "650",
  "planet": "Earth"
}

lookupPretty(ipfs, multiaddrs)

Provides the same results as lookup with the addition of a formatted property that looks like this: Mountain View, CA, United States, Earth.

b-tree

The utility geoip-gen reads csv files provided from GeoLite, and turns them into a 32-way branching b-tree, which is stored as ipfs json objects.

There is a generator included, that can be run with

$ npm run generate

This takes quite a long time to import, but you only need to do it once globally to use the lookup feature.

Example

You can find an example of how to use this in example/lookup.js, which you can use like this:

$ node example/lookup.js 8.8.8.8
Result: {
  "country_name": "USA",
  "country_code": "US",
  "region_code": "CA",
  "city": "Mountain View",
  "postal_code": "94040",
  "latitude": 37.386,
  "longitude": -122.0838,
  "metro_code": "807",
  "area_code": "650",
  "planet": "Earth"
}
Pretty result: Mountain View, CA, USA, Earth

Root hash

The current root hash for lookups is defined under GEOIP_ROOT in src/lookup.js

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?

License

MIT

Current Tags

  • 5.0.1                                ...           latest (20 days ago)

25 Versions

  • 5.0.1                                ...           20 days ago
  • 5.0.0                                ...           20 days ago
  • 4.1.0                                ...           4 months ago
  • 4.0.0                                ...           10 months ago
  • 3.0.0                                ...           2 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           5 years ago
  • 1.4.5                                ...           5 years ago
  • 1.4.4                                ...           5 years ago
  • 1.4.3                                ...           5 years ago
  • 1.4.2                                ...           5 years ago
  • 1.4.1                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.3                                ...           5 years ago
  • 1.3.2                                ...           5 years ago
  • 1.3.1                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 34
Last Day 0
Last Week 8
Last Month 37
Dependencies (4)
Dev Dependencies (13)

Copyright 2014 - 2016 © taobao.org |