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

ip-cidr

Package Overview
Dependencies
Maintainers
0
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ip-cidr

Module for working with CIDR (v4, v6)

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
116K
decreased by-19.8%
Maintainers
0
Weekly downloads
 
Created

What is ip-cidr?

The ip-cidr npm package provides utilities for working with IP addresses and CIDR (Classless Inter-Domain Routing) notations. It allows you to perform various operations such as checking if an IP address is within a CIDR range, converting CIDR notations to IP ranges, and more.

What are ip-cidr's main functionalities?

Check if an IP is within a CIDR range

This feature allows you to check if a given IP address is within a specified CIDR range. In this example, '192.168.1.5' is checked against the CIDR range '192.168.1.0/24'.

const IPCIDR = require('ip-cidr');
const cidr = new IPCIDR('192.168.1.0/24');
const isInRange = cidr.contains('192.168.1.5');
console.log(isInRange); // true

Convert CIDR to IP range

This feature converts a CIDR notation to its corresponding IP range. In this example, '192.168.1.0/24' is converted to the range ['192.168.1.0', '192.168.1.255'].

const IPCIDR = require('ip-cidr');
const cidr = new IPCIDR('192.168.1.0/24');
const range = cidr.toRange();
console.log(range); // ['192.168.1.0', '192.168.1.255']

Get the first and last IP addresses in a CIDR range

This feature retrieves the first and last IP addresses within a given CIDR range. In this example, '192.168.1.0/24' is used to get the first and last IP addresses.

const IPCIDR = require('ip-cidr');
const cidr = new IPCIDR('192.168.1.0/24');
const firstIp = cidr.start({ type: 'addressObject' });
const lastIp = cidr.end({ type: 'addressObject' });
console.log(firstIp); // { address: '192.168.1.0', subnetMask: 24 }
console.log(lastIp); // { address: '192.168.1.255', subnetMask: 24 }

Other packages similar to ip-cidr

Keywords

FAQs

Package last updated on 28 Jul 2024

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