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 |
|
7 | Efficient 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 |
|
9 | Works in the browser with [browserify](http://browserify.org/)! This module is used by [WebTorrent](http://webtorrent.io).
|
10 |
|
11 | ## install
|
12 |
|
13 | ```
|
14 | npm install ip-set
|
15 | ```
|
16 |
|
17 | ## usage
|
18 |
|
19 | ```js
|
20 | var ipSet = require('ip-set')(/* optionally pass an array of IP addresses to seed the set with */)
|
21 | ipSet.add(exampleBlockedIP1)
|
22 | ipSet.add(exampleBlockedIP2)
|
23 | var isBlocked = ipSet.contains(exampleBlockedIP2) // isBlocked will be true
|
24 | ```
|
25 |
|
26 | CIDR ip's are also supported
|
27 |
|
28 | ```js
|
29 | ipSet.add(`192.168.1.0/24`);
|
30 | var isBlockedInList= ipSet.contains('192.168.1.0');// isBlockedInList will be true
|
31 | isBlockedInList= 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 |
|
46 | Original 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 |
|
50 | MIT. Copyright (c) Travis Fischer
|
51 |
|
52 | Support 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>
|