Skip to content

Commit 2908763

Browse files
committed
feat(new tool): IPv4/6 CIDR to IP Range
IPv4/6 CIDR to IP Range Reverse fof CorentinTh#802
1 parent 7f5fa00 commit 2908763

File tree

6 files changed

+202
-4
lines changed

6 files changed

+202
-4
lines changed

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ declare module '@vue/runtime-core' {
112112
IconMdiVideo: typeof import('~icons/mdi/video')['default']
113113
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
114114
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
115+
IpCidrToRange: typeof import('./src/tools/ip-cidr-to-range/ip-cidr-to-range.vue')['default']
115116
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
116117
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
117118
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@vueuse/router": "^10.0.0",
4949
"bcryptjs": "^2.4.3",
5050
"change-case": "^4.1.2",
51+
"cidr-tools": "^7.0.4",
5152
"colord": "^2.9.3",
5253
"composerize-ts": "^0.6.2",
5354
"country-code-lookup": "^0.1.0",
@@ -62,6 +63,11 @@
6263
"highlight.js": "^11.7.0",
6364
"iarna-toml-esm": "^3.0.5",
6465
"ibantools": "^4.3.3",
66+
"ip-address": "^9.0.5",
67+
"ip-bigint": "^8.0.2",
68+
"ip-cidr": "^4.0.0",
69+
"is-cidr": "^5.0.3",
70+
"is-ip": "^5.0.1",
6571
"json5": "^2.2.3",
6672
"jwt-decode": "^3.1.2",
6773
"libphonenumber-js": "^1.10.28",

pnpm-lock.yaml

Lines changed: 117 additions & 3 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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import { tool as uuidGenerator } from './uuid-generator';
7777
import { tool as macAddressLookup } from './mac-address-lookup';
7878
import { tool as xmlFormatter } from './xml-formatter';
7979
import { tool as yamlViewer } from './yaml-viewer';
80+
import { tool as ipCidrToRange } from './ip-cidr-to-range';
8081

8182
export const toolsByCategory: ToolCategory[] = [
8283
{
@@ -147,7 +148,15 @@ export const toolsByCategory: ToolCategory[] = [
147148
},
148149
{
149150
name: 'Network',
150-
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
151+
components: [
152+
ipv4SubnetCalculator,
153+
ipv4AddressConverter,
154+
ipv4RangeExpander,
155+
ipCidrToRange,
156+
macAddressLookup,
157+
macAddressGenerator,
158+
ipv6UlaGenerator,
159+
],
151160
},
152161
{
153162
name: 'Math',

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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<script setup lang="ts">
2+
import isCidr from 'is-cidr';
3+
import { expand } from 'cidr-tools';
4+
import { useValidation } from '@/composable/validation';
5+
6+
const rawCIDR = useStorage('ip-cidr-to-range:cidr', '192.168.1.0/24');
7+
8+
const result = computed(() => {
9+
const ips = expand(rawCIDR.value);
10+
if (!ips || !ips.length) {
11+
return undefined;
12+
}
13+
14+
return { startIpAddress: ips.slice(0, 1)[0], endIpAddress: ips.slice(-1)[0] };
15+
});
16+
17+
const cidrValidation = useValidation({
18+
source: rawCIDR,
19+
rules: [{ message: 'Invalid ipv4/6 CIDR', validator: cidr => isCidr(cidr) }],
20+
});
21+
22+
const showResult = computed(() => cidrValidation.isValid && result.value !== undefined);
23+
</script>
24+
25+
<template>
26+
<div>
27+
<c-input-text
28+
v-model:value="rawCIDR"
29+
label="IPv4/6 CIDR (ie, 1.0.0.0/23)"
30+
placeholder="IPv4/6 CIDR (ie, 1.0.0.0/23)"
31+
:validation="cidrValidation"
32+
clearable
33+
/>
34+
35+
<c-card v-if="showResult" title="IPv4/6 range" mt-4>
36+
<input-copyable
37+
label="Start IP Address"
38+
label-position="left"
39+
label-width="150px"
40+
label-align="right"
41+
42+
:value="result?.startIpAddress"
43+
disabled mb-2
44+
/>
45+
<input-copyable
46+
label="End IP Address"
47+
label-position="left"
48+
label-width="150px"
49+
label-align="right"
50+
51+
:value="result?.endIpAddress"
52+
disabled mb-2
53+
/>
54+
</c-card>
55+
</div>
56+
</template>

0 commit comments

Comments
 (0)