From cfbe604aaa070890c1455a924cc706e814fa93c0 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sat, 21 Sep 2024 14:12:19 +0200 Subject: Add netmask details and update header --- app/page.tsx | 66 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index c6af996..459609b 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,7 +1,7 @@ "use client" import React, { useState } from 'react'; -// import { Netmask } from 'netmask'; +import { Netmask } from 'netmask'; export default function Cidr() { const [ip, setIp] = useState([10, 88, 135, 144]); @@ -23,19 +23,36 @@ export default function Cidr() { setIp(newIp); } + const pretty = ip.join('.') + '/' + cidr; + const netmask = new Netmask(pretty); + + const details = { + "Netmask": netmask.mask, + "CIDR Base IP": netmask.base, + "Broadcast IP": netmask.broadcast, + "Count": netmask.size.toLocaleString(), + "First Usable IP": netmask.first, + "Last Usable IP": netmask.last + } + return (
-

IP / CIDR Visualizer

-

- CIDR is a notation for describing - blocks of IP addresses and is used heavily in various networking configurations. IP addresses contain 4 - octets, each consisting of 8 bits giving values between 0 and 255. The decimal value that comes after the - slash is the number of bits consisting of the routing prefix. This in turn can be translated into a netmask, - and also designates how many available addresses are in the block. -

+

+ IP / CIDR Calculator +

+ +
+

CIDR is a notation for describing + blocks of IP addresses and is used heavily in various networking configurations.

+

IP addresses contain 4 + octets, each consisting of 8 bits giving values between 0 and 255. The decimal value that comes after the + slash is the number of bits consisting of the routing prefix.

+

This in turn can be translated into a netmask, + and also designates how many available addresses are in the block.

+
-
+
{ip.map((octet, i) => (
-
- IP Address: - {ip.join('.')} - CIDR: /{cidr} +
+ {Object.entries(details).map(([label, val]) => +
+
{val}
+
{label}
+
) + }
- -
+ +
); } -- cgit v1.3.1