UNPKG

1.99 kBMarkdownView Raw
1# ip-set [![travis](https://img.shields.io/travis/transitive-bullshit/ip-set.svg)](https://travis-ci.org/transitive-bullshit/ip-set) [![npm](https://img.shields.io/npm/v/ip-set.svg)](https://npmjs.org/package/ip-set)
2
3### IP Address Set
4
5[![browser support](https://ci.testling.com/transitive-bullshit/ip-set.png)](https://ci.testling.com/transitive-bullshit/ip-set)
6
7Efficient mutable set data structure optimized for use with IPv4 and IPv6 addresses. The primary use case is for working with potentially large IP blacklists.
8
9Works in the browser with [browserify](http://browserify.org/)! This module is used by [WebTorrent](http://webtorrent.io).
10
11## install
12
13```
14npm install ip-set
15```
16
17## usage
18
19```js
20var ipSet = require('ip-set')(/* optionally pass an array of IP addresses to seed the set with */)
21ipSet.add(exampleBlockedIP1)
22ipSet.add(exampleBlockedIP2)
23var isBlocked = ipSet.contains(exampleBlockedIP2) // isBlocked will be true
24```
25
26CIDR ip's are also supported
27
28```js
29ipSet.add(`192.168.1.0/24`);
30var isBlockedInList= ipSet.contains('192.168.1.0');// isBlockedInList will be true
31isBlockedInList= ipSet.contains('192.168.1.255');// isBlockedInList will be true
32```
33
34
35## todo
36(prioritized highest to lowest)
37
38- [x] Port IPv4 implementation from `torrent-stream`
39- [x] Add basic tests
40- [x] Support CIDR notation
41- [ ] Support IPv6
42- [ ] Investigate potential use of [node-iptrie](https://github.com/postwait/node-iptrie)
43
44## credits
45
46Original interval-tree written by [galedric](https://github.com/galedric) for [torrent-stream](https://github.com/mafintosh/torrent-stream). Ported to an isolated npm module by [transitive-bullshit](https://github.com/transitive-bullshit) for [webtorrent](http://webtorrent.io).
47
48## license
49
50MIT. Copyright (c) Travis Fischer
51
52Support my OSS work by <a href="https://twitter.com/transitive_bs">following me on twitter <img src="https://storage.googleapis.com/saasify-assets/twitter-logo.svg" alt="twitter" height="24px" align="center"></a>