Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
cidr-regex
Advanced tools
The 'cidr-regex' npm package provides regular expressions for matching and validating CIDR (Classless Inter-Domain Routing) notation IP addresses, both IPv4 and IPv6. This is useful for network configuration, validation, and parsing tasks.
Match CIDR Notation
This feature allows you to check if a given string matches the CIDR notation for IPv4 or IPv6 addresses.
const cidrRegex = require('cidr-regex');
const ip = '192.168.0.1/24';
const isMatch = cidrRegex().test(ip);
console.log(isMatch); // true
Extract CIDR Notation
This feature allows you to extract all CIDR notations from a given string.
const cidrRegex = require('cidr-regex');
const text = 'Here is a CIDR: 192.168.0.1/24 and another one: 10.0.0.0/8';
const matches = text.match(cidrRegex());
console.log(matches); // ['192.168.0.1/24', '10.0.0.0/8']
IPv4 and IPv6 Support
This feature provides separate methods for matching IPv4 and IPv6 CIDR notations.
const cidrRegex = require('cidr-regex');
const ipv4 = '192.168.0.1/24';
const ipv6 = '2001:db8::/32';
console.log(cidrRegex.v4().test(ipv4)); // true
console.log(cidrRegex.v6().test(ipv6)); // true
The 'ip-cidr' package provides utilities for parsing, manipulating, and validating CIDR notations. It offers more comprehensive functionality compared to 'cidr-regex', including methods for subnet calculations and IP range generation.
The 'cidr-js' package focuses on CIDR block calculations and IP address manipulations. It provides methods for checking if an IP is within a CIDR range, splitting CIDR blocks, and more. It is more feature-rich in terms of network calculations compared to 'cidr-regex'.
The 'netmask' package is used for IP address and network mask calculations. It allows for parsing and manipulating IP ranges and CIDR blocks, offering more advanced network-related functionalities than 'cidr-regex'.
Regular expression for matching IP addresses in CIDR notation
$ npm i cidr-regex
import cidrRegex from "cidr-regex";
// Contains a CIDR IP address?
cidrRegex().test("foo 192.168.0.1/24");
//=> true
// Is a CIDR IP address?
cidrRegex({exact: true}).test("foo 192.168.0.1/24");
//=> false
cidrRegex.v6({exact: true}).test("1:2:3:4:5:6:7:8/64");
//=> true
// Extract CIDRs from string
"foo 192.168.0.1/24 bar 1:2:3:4:5:6:7:8/64 baz".match(cidrRegex());
//=> ["192.168.0.1/24", "1:2:3:4:5:6:7:8/64"]
Returns a regex for matching both IPv4 and IPv6 CIDR IP addresses.
Returns a regex for matching IPv4 CIDR IP addresses.
Returns a regex for matching IPv6 CIDR IP addresses.
Type: boolean
Default: false
(Matches any CIDR IP address in a string)
Only match an exact string. Useful with RegExp#test()
to check if a string is a CIDR IP address.
© silverwind, distributed under BSD licence
Based on previous work by Felipe Apostol
FAQs
Regular expression for matching IP addresses in CIDR notation
The npm package cidr-regex receives a total of 584,588 weekly downloads. As such, cidr-regex popularity was classified as popular.
We found that cidr-regex demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.