Skip to content

Commit 86feffa

Browse files
committed
Merge branch 'feat/ipv4-subnet-enh' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/utils/ip.test.ts
2 parents 57e8f5f + 328afe5 commit 86feffa

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

pnpm-lock.yaml

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

src/tools/ipv4-address-converter/ipv4-address-converter.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script setup lang="ts">
22
import { convertBase } from '../integer-base-converter/integer-base-converter.model';
3+
import { getIPClass } from '../ipv4-subnet-calculator/ipv4-subnet-calculator.models';
34
import { ipv4ToInt, ipv4ToIpv6, isValidIpv4 } from './ipv4-address-converter.service';
5+
import { getIPNetworkType, to6to4Prefix, toARPA, toIPv4MappedAddressDecimal } from '@/utils/ip';
46
import { useValidation } from '@/composable/validation';
57
6-
const rawIpAddress = useStorage('ipv4-converter:ip', '192.168.1.1');
8+
const rawIpAddress = useStorage('ipv4-converter:ip', '192.168.1.1'); // NOSONAR
79
810
const convertedSections = computed(() => {
911
const ipInDecimal = ipv4ToInt({ ip: rawIpAddress.value });
@@ -29,6 +31,30 @@ const convertedSections = computed(() => {
2931
label: 'Ipv6 (short): ',
3032
value: ipv4ToIpv6({ ip: rawIpAddress.value, prefix: '::ffff:' }),
3133
},
34+
{
35+
label: 'Ipv6 (decimal): ',
36+
value: toIPv4MappedAddressDecimal(rawIpAddress.value),
37+
},
38+
{
39+
label: '6to4 prefix',
40+
value: to6to4Prefix(rawIpAddress.value),
41+
},
42+
{
43+
label: 'CIDR notation',
44+
value: `${rawIpAddress.value}/32`,
45+
},
46+
{
47+
label: 'ARPA',
48+
value: toARPA(rawIpAddress.value),
49+
},
50+
{
51+
label: 'IP class',
52+
value: getIPClass({ ip: rawIpAddress.value }),
53+
},
54+
{
55+
label: 'Type',
56+
value: getIPNetworkType(rawIpAddress.value),
57+
},
3258
];
3359
});
3460

src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import { getIPClass } from './ipv4-subnet-calculator.models';
66
import { withDefaultOnError } from '@/utils/defaults';
77
import { isNotThrowing } from '@/utils/boolean';
88
import SpanCopyable from '@/components/SpanCopyable.vue';
9+
import { getIPNetworkType, getNetworksCount, getSubnets, parseAsCIDR, to6to4Prefix, toARPA, toIPv4MappedAddress, toIPv4MappedAddressDecimal } from '@/utils/ip';
910
1011
const ip = useStorage('ipv4-subnet-calculator:ip', '192.168.0.1/24');
1112
12-
const getNetworkInfo = (address: string) => new Netmask(address.trim());
13+
const getNetworkInfo = (address: string) => new Netmask(parseAsCIDR(address.trim()) || address.trim());
1314
1415
const networkInfo = computed(() => withDefaultOnError(() => getNetworkInfo(ip.value), undefined));
1516
1617
const ipValidationRules = [
1718
{
1819
message: 'We cannot parse this address, check the format',
19-
validator: (value: string) => isNotThrowing(() => getNetworkInfo(value.trim())),
20+
validator: (value: string) => isNotThrowing(() => getNetworkInfo(value)),
2021
},
2122
];
2223
@@ -53,6 +54,14 @@ const sections: {
5354
label: 'Network size',
5455
getValue: ({ size }) => String(size),
5556
},
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+
},
5665
{
5766
label: 'First address',
5867
getValue: ({ first }) => first,
@@ -66,11 +75,31 @@ const sections: {
6675
getValue: ({ broadcast }) => broadcast,
6776
undefinedFallback: 'No broadcast address with this mask',
6877
},
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+
},
6994
{
7095
label: 'IP class',
7196
getValue: ({ base: ip }) => getIPClass({ ip }),
7297
undefinedFallback: 'Unknown class type',
7398
},
99+
{
100+
label: 'Type',
101+
getValue: ({ base: ip }) => getIPNetworkType(ip),
102+
},
74103
];
75104
76105
function switchToBlock({ count = 1 }: { count?: number }) {
@@ -86,7 +115,7 @@ function switchToBlock({ count = 1 }: { count?: number }) {
86115
<div>
87116
<c-input-text
88117
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)"
90119
placeholder="The ipv4 address..."
91120
:validation-rules="ipValidationRules"
92121
mb-4

0 commit comments

Comments
 (0)