@@ -6,17 +6,18 @@ import { getIPClass } from './ipv4-subnet-calculator.models';
6
6
import { withDefaultOnError } from ' @/utils/defaults' ;
7
7
import { isNotThrowing } from ' @/utils/boolean' ;
8
8
import SpanCopyable from ' @/components/SpanCopyable.vue' ;
9
+ import { getIPNetworkType , getNetworksCount , getSubnets , parseAsCIDR , to6to4Prefix , toARPA , toIPv4MappedAddress , toIPv4MappedAddressDecimal } from ' @/utils/ip' ;
9
10
10
11
const ip = useStorage (' ipv4-subnet-calculator:ip' , ' 192.168.0.1/24' );
11
12
12
- const getNetworkInfo = (address : string ) => new Netmask (address .trim ());
13
+ const getNetworkInfo = (address : string ) => new Netmask (parseAsCIDR ( address . trim ()) || address .trim ());
13
14
14
15
const networkInfo = computed (() => withDefaultOnError (() => getNetworkInfo (ip .value ), undefined ));
15
16
16
17
const ipValidationRules = [
17
18
{
18
19
message: ' We cannot parse this address, check the format' ,
19
- validator : (value : string ) => isNotThrowing (() => getNetworkInfo (value . trim () )),
20
+ validator : (value : string ) => isNotThrowing (() => getNetworkInfo (value )),
20
21
},
21
22
];
22
23
@@ -53,6 +54,14 @@ const sections: {
53
54
label: ' Network size' ,
54
55
getValue : ({ size }) => String (size ),
55
56
},
57
+ {
58
+ label: ' Subnets count' ,
59
+ getValue : ({ base : ip , bitmask }) => getNetworksCount (` ${ip }/${bitmask } ` )?.toString () || ' ' ,
60
+ },
61
+ {
62
+ label: ' Subnets' ,
63
+ getValue : ({ base : ip , bitmask }) => getSubnets (` ${ip }/${bitmask } ` ).join (' , ' ),
64
+ },
56
65
{
57
66
label: ' First address' ,
58
67
getValue : ({ first }) => first ,
@@ -66,11 +75,31 @@ const sections: {
66
75
getValue : ({ broadcast }) => broadcast ,
67
76
undefinedFallback: ' No broadcast address with this mask' ,
68
77
},
78
+ {
79
+ label: ' ARPA' ,
80
+ getValue : ({ base : ip }) => toARPA (ip ),
81
+ },
82
+ {
83
+ label: ' IPv4 Mapped Address' ,
84
+ getValue : ({ base : ip }) => toIPv4MappedAddress (ip ),
85
+ },
86
+ {
87
+ label: ' IPv4 Mapped Address (decimal)' ,
88
+ getValue : ({ base : ip }) => toIPv4MappedAddressDecimal (ip ),
89
+ },
90
+ {
91
+ label: ' 6to4 prefix' ,
92
+ getValue : ({ base : ip }) => to6to4Prefix (ip ),
93
+ },
69
94
{
70
95
label: ' IP class' ,
71
96
getValue : ({ base : ip }) => getIPClass ({ ip }),
72
97
undefinedFallback: ' Unknown class type' ,
73
98
},
99
+ {
100
+ label: ' Type' ,
101
+ getValue : ({ base : ip }) => getIPNetworkType (ip ),
102
+ },
74
103
];
75
104
76
105
function switchToBlock({ count = 1 }: { count? : number }) {
@@ -86,7 +115,7 @@ function switchToBlock({ count = 1 }: { count?: number }) {
86
115
<div >
87
116
<c-input-text
88
117
v-model:value =" ip"
89
- label =" An IPv4 address with or without mask"
118
+ label =" An IPv4 address with or without mask (CIDR/IP Range/Wildcard IP/IP Mask) "
90
119
placeholder =" The ipv4 address..."
91
120
:validation-rules =" ipValidationRules"
92
121
mb-4
0 commit comments