Skip to content

Commit e3fdf35

Browse files
committed
Merge branch 'feat/ip-cidr-to-range' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
2 parents 133d8b3 + a0141dc commit e3fdf35

File tree

9 files changed

+661
-2
lines changed

9 files changed

+661
-2
lines changed

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"change-case": "^4.1.2",
118118
"chatgpt-prompt-splitter": "^1.0.5",
119119
"chinesegen": "^0.3.3",
120+
"cidr-tools": "^7.0.4",
120121
"colord": "^2.9.3",
121122
"composerize": "^1.6.6",
122123
"composerize-ts": "^0.6.2",
@@ -198,6 +199,12 @@
198199
"js-beautify": "^1.15.1",
199200
"image-to-ascii-art": "^0.0.4",
200201
"jpeg-quality-estimator": "^1.0.1",
202+
"ip-address": "^9.0.5",
203+
"ip-bigint": "^8.0.2",
204+
"ip-cidr": "^4.0.0",
205+
"ip-matching": "^2.1.2",
206+
"is-cidr": "^5.0.3",
207+
"is-ip": "^5.0.1",
201208
"json5": "^2.2.3",
202209
"jsonpath": "^1.1.1",
203210
"jsonar-mod": "^1.9.0",

pnpm-lock.yaml

Lines changed: 110 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ import { tool as barcodeReader } from './barcode-reader';
205205
import { tool as barcodeGenerator } from './barcode-generator';
206206
import { tool as htmlToMarkdown } from './html-to-markdown';
207207
import { tool as pdfUnlock } from './pdf-unlock';
208+
import { tool as ipCidrToRange } from './ip-cidr-to-range';
208209

209210
export const toolsByCategory: ToolCategory[] = [
210211
{
@@ -417,6 +418,11 @@ export const toolsByCategory: ToolCategory[] = [
417418
punycodeConverter,
418419
sslCertConverter,
419420
websocketTester,
421+
ipv4RangeExpander,
422+
ipCidrToRange,
423+
macAddressLookup,
424+
macAddressGenerator,
425+
ipv6UlaGenerator,
420426
],
421427
},
422428
{

src/tools/ip-cidr-to-range/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Binary } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Ipv4/6 CIDR to IP Range Calculator',
6+
path: '/ip-cidr-to-range',
7+
description: 'Calculate IP Range from a CIDR (IPv4/6)',
8+
keywords: ['ipv4', 'ipv6', 'cidr'],
9+
component: () => import('./ip-cidr-to-range.vue'),
10+
icon: Binary,
11+
createdAt: new Date('2024-01-10'),
12+
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import isCidr from 'is-cidr';
3+
import { expand } from 'cidr-tools';
4+
import { getIPNetworkType, parseAsCIDR } from '@/utils/ip';
5+
import { useValidation } from '@/composable/validation';
6+
7+
const rawCIDR = useStorage('ip-cidr-to-range:cidr', '192.168.1.0/24'); // NOSONAR
8+
9+
const result = computed(() => {
10+
const parsedCIDR = parseAsCIDR(rawCIDR.value) || rawCIDR.value;
11+
const ips = expand(parsedCIDR);
12+
if (!ips || !ips.length) {
13+
return undefined;
14+
}
15+
16+
return {
17+
startIpAddress: ips.slice(0, 1)[0],
18+
endIpAddress: ips.slice(-1)[0],
19+
parsedCIDR,
20+
networkType: getIPNetworkType(ips.slice(0, 1)[0]) || 'Public',
21+
};
22+
});
23+
24+
const cidrValidation = useValidation({
25+
source: rawCIDR,
26+
rules: [{ message: 'Invalid ipv4/6 CIDR', validator: cidr => isCidr(parseAsCIDR(cidr) || cidr) }],
27+
});
28+
29+
const showResult = computed(() => cidrValidation.isValid && result.value !== undefined);
30+
</script>
31+
32+
<template>
33+
<div>
34+
<c-input-text
35+
v-model:value="rawCIDR"
36+
label="IPv4/6 CIDR (ie, 1.0.0.0/23 or 1.1.1.1/255.255.252.0 or 1.1.1.1-2.2.2.2 or 10.0.0.*)"
37+
placeholder="IPv4/6 CIDR (ie, 1.0.0.0/23 or 1.1.1.1/255.255.252.0 or 1.1.1.1-2.2.2.2 or 10.0.0.*)"
38+
:validation="cidrValidation"
39+
clearable
40+
/>
41+
42+
<c-card v-if="showResult" title="Resulting CIDR" mt-4>
43+
<input-copyable
44+
label="CIDR"
45+
label-position="left"
46+
label-width="150px"
47+
label-align="right"
48+
49+
:value="result?.parsedCIDR"
50+
disabled mb-2
51+
/>
52+
</c-card>
53+
54+
<c-card v-if="showResult" title="IPv4/6 range" mt-4>
55+
<input-copyable
56+
label="Start IP Address"
57+
label-position="left"
58+
label-width="150px"
59+
label-align="right"
60+
61+
:value="result?.startIpAddress"
62+
disabled mb-2
63+
/>
64+
<input-copyable
65+
label="End IP Address"
66+
label-position="left"
67+
label-width="150px"
68+
label-align="right"
69+
70+
:value="result?.endIpAddress"
71+
disabled mb-2
72+
/>
73+
74+
<input-copyable
75+
label="Network type"
76+
label-position="left"
77+
label-width="150px"
78+
label-align="right"
79+
80+
:value="result?.networkType"
81+
disabled mb-2
82+
/>
83+
</c-card>
84+
</div>
85+
</template>

0 commit comments

Comments
 (0)