npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-ip-collection

v1.0.1

Published

Nodejs ip collection (fast search ip in custom range)

Downloads

68

Readme

node-ip-collection

⭐ fast search ip in range collection ipv4 and ipv6 (it is based on nesting Trie)

  • support range format:
  1. ip CIDR range: 5.151.236.0/23
  2. ip-ip range string: 103.18.156.0-103.18.157.255
  3. ip-ip range bigint: 42540528726795050063891204319802818560-42540528806023212578155541913346768895 or 2548867325-2548867326

base usage

const IpCollection = new require('node-ip-collection');
const ip = new IpCollection({
  useHash: false,     // default value false
  maxSearch: 70,      // default value 70
});

// fixture data
const BotSearch = [
  {
    "range": "103.18.156.0-103.18.157.255\n103.18.158.0-103.18.159.255\n103.197.28.0-103.197.29.255",
    "value": "yandex"
  },
  {
    "range": "103.197.30.0-103.197.31.255\n103.199.184.0-103.199.185.255",
    "value": "yandex"
  },
]
// load fixture
for(let index = 0, len = BotSearch.length; i < len; i++) {
  const {range, value} = BotSearch[i];
  ip.loadFromString(range, value);
}
// find ip in range collection
console.log(ip.lookup('103.18.158.1'))

Methods

| method | description | |:---------------------------------------|:----------------------------------------| | castIpV6ToNum(ip) | convert ipv6 to bingint string | | castIpV4ToNum(ip) | convert ipv4 to bingint string | | castBigIntIpToV4Str(ip) | convert bigint to ipv4 string | | castBigIntIpToV6Str(ip) | convert bigint to ipv6 string | | loadFromString(rangeList, value) | load data to database | | lookup(ip, all) | find data | | import(data) | import data from result export() method | | export() | export data to json string | | insertRange(start, end, ipType, value) | insert range to database | | clear() | clear all data |

Benchmark maxmind v4 city

full load data ~58sec (yes it’s long, but don’t rush to give up)

await (new Promise((resolve, reject) => {
  fs.createReadStream(__dirname + '/GeoLite2-City-Blocks-IPv4.csv')
  .pipe(csv.parse({headers: true}))
  .on('error', error => console.error(error))
  .on('data', row => {
  	 ip.loadFromString(row.network, row.geoname_id)
  })
  .on('end', () => {
  	resolve();
  })
}));

search geoname_id ~0.736ms

console.time('test')
console.log('result', '151.236.160.253', ip.lookup('151.236.160.253', true));
console.timeEnd('test')
  • is export data to json and load data from json
  • full load data ~8sec
  • search geoname_id ~0.736ms

Misc Wiki