Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ip-filter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ip-filter

Validates valid IPs (IPv4 and IPv6) using [micromatch][] - glob patterns, RegExp, string or array of globs. If match returns the IP, otherwise null.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
955
decreased by-10.91%
Maintainers
1
Weekly downloads
 
Created
Source

ip-filter npmjs.com The MIT License

Validates valid IPs (IPv4 and IPv6) using micromatch - glob patterns, RegExp, string or array of globs. If match returns the IP, otherwise null.

code climate standard code style travis build status coverage status dependency status

You might also be interested in is-match-ip, to-object-path, to-file-path or koa-ip-filter.

Install

npm i ip-filter --save

Usage

For more use-cases see the tests

const ipFilter = require('ip-filter')

ipFilter

Filter ip against glob patterns, using micromatch under the hood, so options are passed to it.

Params

  • ip {String}: Accepts only valid IPs by default
  • patterns {String|Array|RegExp|Function|Object}: Basically everything that is-match can accept.
  • options {Object}: Pass strict: false if want to validate non-ip values, also passed to is-match.
  • returns {String|null}: If not match returns null, otherwise the passed ip.

Example

var ipFilter = require('ip-filter')

console.log(ipFilter('123.77.34.89', '123.??.34.8*')) // => '123.77.34.89'
console.log(ipFilter('123.222.34.88', '123.??.34.8*')) // => null
console.log(ipFilter('123.222.33.1', ['123.*.34.*', '*.222.33.*'])) // => '123.222.33.1'

// should notice the difference
console.log(ipFilter('123.222.34.88', ['123.*.34.*', '!123.222.**']))
// => null
console.log(ipFilter('123.222.34.88', ['123.*.34.*', '!123.222.*']))
// => '123.222.34.88'

//
// NON-STRICT mode
//

var res = ipFilter('x-koaip', ['*-koaip', '!foo-koa*'], { strict: false })
console.log(res) // => 'x-koaip'

var res = ipFilter('x-koa.foo', ['*-koa.*', '!foo-koa.*'], { strict: false })
console.log(res) // => 'x-koa.foo'

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Keywords

FAQs

Package last updated on 06 Oct 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc