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

insubnet

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insubnet

Check an IP(v4 or v6) against a subnet.

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
96
decreased by-66.08%
Maintainers
1
Weekly downloads
 
Created
Source

inSubnet (v0.0.4)

Install: npm install insubnet

This project is Unlicensed. In other words, I don't care what you do with it. However, if you make something interesting, I would like to check it out.

Browser example at http://louist.github.io/inSubnet/example.html.

Functions:

Examples in `./examples/` folder.

inSubnet.Auto(ip, subnet[, mask]) - Check to find out if <ip> is in <subnet>. Works with IPv4 and IPv6. Returns boolean.
     Examples: inSubnet.Auto('1.2.3.4','1.2.0.0/16'); // true
               inSubnet.Auto('1.2.3.4','1.2.0.0','16'); // true
               inSubnet.Auto('1.4.3.4','1.2.0.0','16'); // false

inSubnet.IPv4(ip, subnet[, mask]) - Same as "Auto()" but for IPv4 only. - Returns boolean.
     Examples: See "Auto()" examples.

inSubnet.IPv6(ip, subnet[, mask]) - Same as "Auto()" but for IPv6 only. - Returns boolean.
     Examples: inSubnet.IPv6('2400:cb00::123','2400:cb00::/32'); // true
               inSubnet.IPv6('2400:cb00::123','2400:cb00::','32'); // true
               inSubnet.IPv6('2500:cb00::123','2400:cb00::','32'); // false

inSubnet.isIP(string) - Check if <string> is an IP address. Works for IPv6 and IPv4. - Returns boolean.
     Examples: inSubnet.isIP("127.0.0.1"); // true
               inSubnet.isIP("afd::1"); // true
               inSubnet.isIP("asd::1"); // false

inSubnet.isIPv4(string) - Same as "isIP()" but for IPv4 only. - Returns boolean.
     Examples: inSubnet.isIPv4("127.0.0.1"); // true
               inSubnet.isIPv4("127.0.0.256"); // false

inSubnet.isIPv6(string) - Same as "isIP()" but for IPv6 only. - Returns boolean.
     Examples: inSubnet.isIPv6("adf::1"); // true
               inSubnet.isIPv6("asf::1"); // false

inSubnet.Expand(ipv6) - Expands an IPv6. - Returns IPv6 or false.
     Examples: inSubnet.Expand("afd::1"); // 0afd:0000:0000:0000:0000:0000:0000:0001
               inSubnet.Expand("2001:4860:4860::8888"); // 2001:4860:4860:0000:0000:0000:0000:8888

inSubnet.Validate(ip[, subnets]) - Check <ip> or an Array of IPs against an array of subnets set by "setSubnets()".
                                  If <subnets> is passed, uses "setSubnets()". - Returns boolean or an Array of boolean.
     Examples: inSubnet.Validate('127.0.0.1',['127.0.0.1/32','adf::1/32']);  // true
               inSubnet.Validate(['127.0.0.1','127.0.0.2'],['127.0.0.1/32']); // [true,false]

inSubnet.Filter(array[, subnets]) - Filter an Array of IP addresses against subnets set with "setSubnets()" - Returns an Array of valid IPs.
                                   If <subnets> is passed, uses "setSubnets()". - Returns IP or false, Array of valid IPs.
     Examples: inSubnet.Filter(['127.0.0.1','adf::1','127.0.0.2'],['127.0.0.1/32','adf::1/32']); // ['127.0.0.1','adf::1']
               inSubnet.Filter('127.0.0.1',['127.0.0.1/32','adf::1/32']); // 127.0.0.1
               inSubnet.Filter('127.0.0.2',['127.0.0.1/32','adf::1/32']); // false

inSubnet.setSubnets(subnets) - Set a list of subnets for "Validate()".
                               WARNING: Overrides all previous "setSubnets()" calls. - Returns boolean.
     Examples: inSubnet.setSubnets(["192.168.1.0/30","::1/32"]); // true
               inSubnet.setSubnets(["not","subnets","subnet/32"]); // false

TODO:

  • Figure out what should be in the TODO and then write it! (Done!?)
  • Write a better README! (Is this happening?)
  • Write a simple HTTP example for CloudFlare. (Look in ./examples/cloudflare.js)
  • Make "Exporter" better.

Keywords

FAQs

Package last updated on 08 Nov 2013

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