1
1
<script setup lang="ts">
2
2
import isCidr from ' is-cidr' ;
3
3
import { expand } from ' cidr-tools' ;
4
+ import { getIPNetworkType , parseAsCIDR } from ' @/utils/ip' ;
4
5
import { useValidation } from ' @/composable/validation' ;
5
6
6
- const rawCIDR = useStorage (' ip-cidr-to-range:cidr' , ' 192.168.1.0/24' );
7
+ const rawCIDR = useStorage (' ip-cidr-to-range:cidr' , ' 192.168.1.0/24' ); // NOSONAR
7
8
8
9
const result = computed (() => {
9
- const ips = expand (rawCIDR .value );
10
+ const parsedCIDR = parseAsCIDR (rawCIDR .value ) || rawCIDR .value ;
11
+ const ips = expand (parsedCIDR );
10
12
if (! ips || ! ips .length ) {
11
13
return undefined ;
12
14
}
13
15
14
- return { startIpAddress: ips .slice (0 , 1 )[0 ], endIpAddress: ips .slice (- 1 )[0 ] };
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
+ };
15
22
});
16
23
17
24
const cidrValidation = useValidation ({
18
25
source: rawCIDR ,
19
- rules: [{ message: ' Invalid ipv4/6 CIDR' , validator : cidr => isCidr (cidr ) }],
26
+ rules: [{ message: ' Invalid ipv4/6 CIDR' , validator : cidr => isCidr (parseAsCIDR ( cidr ) || cidr ) }],
20
27
});
21
28
22
29
const showResult = computed (() => cidrValidation .isValid && result .value !== undefined );
@@ -26,12 +33,24 @@ const showResult = computed(() => cidrValidation.isValid && result.value !== und
26
33
<div >
27
34
<c-input-text
28
35
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)"
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.* )"
31
38
:validation =" cidrValidation"
32
39
clearable
33
40
/>
34
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
+
35
54
<c-card v-if =" showResult" title =" IPv4/6 range" mt-4 >
36
55
<input-copyable
37
56
label =" Start IP Address"
@@ -51,6 +70,16 @@ const showResult = computed(() => cidrValidation.isValid && result.value !== und
51
70
:value =" result?.endIpAddress"
52
71
disabled mb-2
53
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
+ />
54
83
</c-card >
55
84
</div >
56
85
</template >
0 commit comments