Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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 581,436 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.