mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
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
This commit is contained in:
commit
86feffa5e2
3 files changed
+61
-5
No files matched your search
Generated
+2
-1
@@ -5297,7 +5297,7 @@ packages:
|
|||||||
/@types/lodash-es@4.17.10:
|
/@types/lodash-es@4.17.10:
|
||||||
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/lodash': 4.14.192
|
'@types/lodash': 4.14.200
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@types/lodash.defaultsdeep@4.6.9:
|
/@types/lodash.defaultsdeep@4.6.9:
|
||||||
@@ -5320,6 +5320,7 @@ packages:
|
|||||||
|
|
||||||
/@types/lodash@4.14.192:
|
/@types/lodash@4.14.192:
|
||||||
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/lodash@4.14.200:
|
/@types/lodash@4.14.200:
|
||||||
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { convertBase } from '../integer-base-converter/integer-base-converter.model';
|
import { convertBase } from '../integer-base-converter/integer-base-converter.model';
|
||||||
|
import { getIPClass } from '../ipv4-subnet-calculator/ipv4-subnet-calculator.models';
|
||||||
import { ipv4ToInt, ipv4ToIpv6, isValidIpv4 } from './ipv4-address-converter.service';
|
import { ipv4ToInt, ipv4ToIpv6, isValidIpv4 } from './ipv4-address-converter.service';
|
||||||
|
import { getIPNetworkType, to6to4Prefix, toARPA, toIPv4MappedAddressDecimal } from '@/utils/ip';
|
||||||
import { useValidation } from '@/composable/validation';
|
import { useValidation } from '@/composable/validation';
|
||||||
|
|
||||||
const rawIpAddress = useStorage('ipv4-converter:ip', '192.168.1.1');
|
const rawIpAddress = useStorage('ipv4-converter:ip', '192.168.1.1'); // NOSONAR
|
||||||
|
|
||||||
const convertedSections = computed(() => {
|
const convertedSections = computed(() => {
|
||||||
const ipInDecimal = ipv4ToInt({ ip: rawIpAddress.value });
|
const ipInDecimal = ipv4ToInt({ ip: rawIpAddress.value });
|
||||||
@@ -29,6 +31,30 @@ const convertedSections = computed(() => {
|
|||||||
label: 'Ipv6 (short): ',
|
label: 'Ipv6 (short): ',
|
||||||
value: ipv4ToIpv6({ ip: rawIpAddress.value, prefix: '::ffff:' }),
|
value: ipv4ToIpv6({ ip: rawIpAddress.value, prefix: '::ffff:' }),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Ipv6 (decimal): ',
|
||||||
|
value: toIPv4MappedAddressDecimal(rawIpAddress.value),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '6to4 prefix',
|
||||||
|
value: to6to4Prefix(rawIpAddress.value),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'CIDR notation',
|
||||||
|
value: `${rawIpAddress.value}/32`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'ARPA',
|
||||||
|
value: toARPA(rawIpAddress.value),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'IP class',
|
||||||
|
value: getIPClass({ ip: rawIpAddress.value }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Type',
|
||||||
|
value: getIPNetworkType(rawIpAddress.value),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,18 @@ import { getIPClass } from './ipv4-subnet-calculator.models';
|
|||||||
import { withDefaultOnError } from '@/utils/defaults';
|
import { withDefaultOnError } from '@/utils/defaults';
|
||||||
import { isNotThrowing } from '@/utils/boolean';
|
import { isNotThrowing } from '@/utils/boolean';
|
||||||
import SpanCopyable from '@/components/SpanCopyable.vue';
|
import SpanCopyable from '@/components/SpanCopyable.vue';
|
||||||
|
import { getIPNetworkType, getNetworksCount, getSubnets, parseAsCIDR, to6to4Prefix, toARPA, toIPv4MappedAddress, toIPv4MappedAddressDecimal } from '@/utils/ip';
|
||||||
|
|
||||||
const ip = useStorage('ipv4-subnet-calculator:ip', '192.168.0.1/24');
|
const ip = useStorage('ipv4-subnet-calculator:ip', '192.168.0.1/24');
|
||||||
|
|
||||||
const getNetworkInfo = (address: string) => new Netmask(address.trim());
|
const getNetworkInfo = (address: string) => new Netmask(parseAsCIDR(address.trim()) || address.trim());
|
||||||
|
|
||||||
const networkInfo = computed(() => withDefaultOnError(() => getNetworkInfo(ip.value), undefined));
|
const networkInfo = computed(() => withDefaultOnError(() => getNetworkInfo(ip.value), undefined));
|
||||||
|
|
||||||
const ipValidationRules = [
|
const ipValidationRules = [
|
||||||
{
|
{
|
||||||
message: 'We cannot parse this address, check the format',
|
message: 'We cannot parse this address, check the format',
|
||||||
validator: (value: string) => isNotThrowing(() => getNetworkInfo(value.trim())),
|
validator: (value: string) => isNotThrowing(() => getNetworkInfo(value)),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -53,6 +54,14 @@ const sections: {
|
|||||||
label: 'Network size',
|
label: 'Network size',
|
||||||
getValue: ({ size }) => String(size),
|
getValue: ({ size }) => String(size),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Subnets count',
|
||||||
|
getValue: ({ base: ip, bitmask }) => getNetworksCount(`${ip}/${bitmask}`)?.toString() || '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Subnets',
|
||||||
|
getValue: ({ base: ip, bitmask }) => getSubnets(`${ip}/${bitmask}`).join(', '),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'First address',
|
label: 'First address',
|
||||||
getValue: ({ first }) => first,
|
getValue: ({ first }) => first,
|
||||||
@@ -66,11 +75,31 @@ const sections: {
|
|||||||
getValue: ({ broadcast }) => broadcast,
|
getValue: ({ broadcast }) => broadcast,
|
||||||
undefinedFallback: 'No broadcast address with this mask',
|
undefinedFallback: 'No broadcast address with this mask',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'ARPA',
|
||||||
|
getValue: ({ base: ip }) => toARPA(ip),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'IPv4 Mapped Address',
|
||||||
|
getValue: ({ base: ip }) => toIPv4MappedAddress(ip),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'IPv4 Mapped Address (decimal)',
|
||||||
|
getValue: ({ base: ip }) => toIPv4MappedAddressDecimal(ip),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '6to4 prefix',
|
||||||
|
getValue: ({ base: ip }) => to6to4Prefix(ip),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'IP class',
|
label: 'IP class',
|
||||||
getValue: ({ base: ip }) => getIPClass({ ip }),
|
getValue: ({ base: ip }) => getIPClass({ ip }),
|
||||||
undefinedFallback: 'Unknown class type',
|
undefinedFallback: 'Unknown class type',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Type',
|
||||||
|
getValue: ({ base: ip }) => getIPNetworkType(ip),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
function switchToBlock({ count = 1 }: { count?: number }) {
|
function switchToBlock({ count = 1 }: { count?: number }) {
|
||||||
@@ -86,7 +115,7 @@ function switchToBlock({ count = 1 }: { count?: number }) {
|
|||||||
<div>
|
<div>
|
||||||
<c-input-text
|
<c-input-text
|
||||||
v-model:value="ip"
|
v-model:value="ip"
|
||||||
label="An IPv4 address with or without mask"
|
label="An IPv4 address with or without mask (CIDR/IP Range/Wildcard IP/IP Mask)"
|
||||||
placeholder="The ipv4 address..."
|
placeholder="The ipv4 address..."
|
||||||
:validation-rules="ipValidationRules"
|
:validation-rules="ipValidationRules"
|
||||||
mb-4
|
mb-4
|
||||||
|
|||||||
Reference in new issue
Block a user