Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
futoin-ipset
Advanced tools
Readme
Author: Andrey Galkin
In absence of anything else up-to-date, pure JS and decent for efficient processing of large IP set matching with associative value outcome.
Key features:
Command line:
$ npm install futoin-ipset --save
or:
$ yarn add futoin-ipset --save
The module can be used with webpack
or any other CommonJS packer. However, please
ensure to use ES6->ES5 transpilation for older browsers.
Pre-packed UMD module is available in dist/futoin-ipset.js. However, Map polyfill is required for older browsers.
There is no browser use case yet though.
const { IPSet, Address4, Address6 } = require( 'futoin-ipset' );
// universal IPv4/IPv6 set
const ipset = new IPSet();
const Region2 = {}; // any ref can be associated
// cheap operations
ipset.add( '1.2.2.0/23', 'Region 1' );
ipset.add( new Address4('2.3.4.0/24'), Region2 ); // instance of ip-address.Address4 can be also passed
ipset.add( 'abcd::/48', 'Region 1' );
ipset.add( new Address6('bcda::/56'), Region2 ); // ... or instance of ip-address.Address6
ipset.add( '2.3.4.5/32', 'blacklist' );
ipset.add( 'abcd:1234:5678:9abc::/64', 'blacklist' );
ipset.remove( 'bcda::/56' );
// matching
console.log(
ipset.match( '1.2.3.4' ), // 'Region 1',
ipset.match( '2.3.4.1' ), // Region2 ref
ipset.match( new Address4('2.3.4.5') ), // 'blacklist'
ipset.match( 'abcd:1234:5678:9abc::123' ), // 'blacklist'
ipset.match( 'bcda::/56' ), // undefined
);
// just a handy helper
ipset.convertAddress('1.2.3.4') -> instance of Address4
ipset.convertAddress('1.2.3.4/23') -> instance of Address4
ipset.convertAddress('::1') -> instance of Address6
Internally, ipset is a map of prefix lengths to map of network address to referenced value, like:
IP version map of
/23 -> map of
1.2.2.0 -> ref
1.1.0.0 -> ref
/32 -> map of
1.2.3.4 -> ref
Trivial and fast enough pure JS algo:
Determine IPv4 or IPv6 set to use
Go from longest to smallest registered prefix length
Otherwise, return undefined
Universal IPv4/IPv6 wrapper
IPv4 specialization of IPSetBase
IPv6 specialization of IPSetBase
Universal based for IPv4 and IPv6 ipsets
window.FutoIn.ipset - browser-only reference to futoin-ipset module
Universal IPv4/IPv6 wrapper
Kind: global class
Add address to IP set
Kind: instance method of IPSet
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
value | any | any value to associate |
Remove address from IP set
Kind: instance method of IPSet
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
any
Try to match addr against ipset producing associated value
Kind: instance method of IPSet
Returns: any
- value - any associated value or undefined
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
object
Convert raw string or object to implementation instance
Kind: instance method of IPSet
Returns: object
- instance of address implementation
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
IPv4 specialization of IPSetBase
IPv6 specialization of IPSetBase
Universal based for IPv4 and IPv6 ipsets
Kind: global class
C-tor
Param | Type | Description |
---|---|---|
address_impl | class | Address4 or Address6 class reference |
Add address to IP set
Kind: instance method of IPSetBase
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
value | any | any value to associate |
Remove address from IP set
Kind: instance method of IPSetBase
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
any
Try to match addr against ipset producing associated value
Kind: instance method of IPSetBase
Returns: any
- value - any associated value or undefined
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
object
Convert raw string or object to implementation instance
Kind: instance method of IPSetBase
Returns: object
- instance of address implementation
Param | Type | Description |
---|---|---|
addr | string | object | instance implementing ip-address interface or string representation |
window.FutoIn.ipset - browser-only reference to futoin-ipset module
Kind: global variable
documented by jsdoc-to-markdown.
FAQs
Pure JS large IP set matching
The npm package futoin-ipset receives a total of 7 weekly downloads. As such, futoin-ipset popularity was classified as not popular.
We found that futoin-ipset demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.