prx-ip-filter

0.0.1 • Public • Published

PRX IP Filter

license npm npm build status

Description

Utility for matching client IP addresses against a list of IP ranges.

This list can be built manually (by adding CIDRs and IP ranges) or loading from an S3 location.

Install

Just npm install --save prx-ip-filter.

Usage

const PrxIpFilter = require('prx-ip-filter');
const filter = new PrxIpFilter();
 
filter.addRange('1.1.1.1', '1.1.255.255', 'Some Datacenter');
filter.addRange('9:9:9:9::', '9:9:9:9:ffff:ffff:ffff:ffff', 'Something Else');
 
console.log(filter.check('1.1.99.99'));
# "Some Datacenter"
console.log(filter.check('9:9:9:9:abcd::'));
# "Something Else"
console.log(filter.check('1.2.1.1'));
# null

You can also serialize the current list of IP ranges to JSON, and load it from JSON:

filter.addRange('1.1.1.1', '1.1.255.255', 'Some Datacenter');
const json = JSON.stringify(filter);
console.log(json);
# "{"names":["Some Datacenter"],"ipv4":["001.001.001.001","001.001.255.255",0],"ipv6":[]}"
 
const filter2 = PrxIpFilter.fromJSON(json);
console.log(filter2.names);
# ["Some Datacenter"]
 
await filter.toFile('/path/to/filters.json');
const filter3 = await PrxIpFilter.fromFile('/path/to/filters.json');
console.log(filter3.names);
# ["Some Datacenter"]

Additionally, you can load load filters from 1 or more CSV files in S3, where each line has the format ipLow,ipHigh,name or cidr,name:

const filter = await PrxIpFilter.fromS3CSV('my-bucket-name', 'some-prefix-path');

Development

Tests are run by Jest, and located in the *.test.js files. Write good tests.

License

MIT License

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feat/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feat/my-new-feature)
  5. Create new Pull Request

Readme

Keywords

Package Sidebar

Install

npm i prx-ip-filter

Weekly Downloads

9

Version

0.0.1

License

MIT

Unpacked Size

17.5 kB

Total Files

7

Last publish

Collaborators

  • cavis