mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-08-09 23:45:18 +02:00
Merge 2fe369a424
into 23f82d956a
This commit is contained in:
commit
6a4f0a8d8d
7 changed files with 277 additions and 1 deletions
1
components.d.ts
vendored
1
components.d.ts
vendored
|
@ -102,6 +102,7 @@ declare module '@vue/runtime-core' {
|
|||
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
||||
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
||||
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
||||
IpRangeToCidr: typeof import('./src/tools/ip-range-to-cidr/ip-range-to-cidr.vue')['default']
|
||||
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
||||
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
|
||||
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
"@vueuse/router": "^10.0.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"change-case": "^4.1.2",
|
||||
"cidr-tools": "^7.0.4",
|
||||
"colord": "^2.9.3",
|
||||
"composerize-ts": "^0.6.2",
|
||||
"country-code-lookup": "^0.1.0",
|
||||
|
@ -64,6 +65,11 @@
|
|||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
"ip-address": "^9.0.5",
|
||||
"ip-bigint": "^8.0.2",
|
||||
"ip-cidr": "^4.0.0",
|
||||
"is-cidr": "^5.0.3",
|
||||
"is-ip": "^5.0.1",
|
||||
"json5": "^2.2.3",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"libphonenumber-js": "^1.10.28",
|
||||
|
|
114
pnpm-lock.yaml
generated
114
pnpm-lock.yaml
generated
|
@ -47,6 +47,9 @@ dependencies:
|
|||
change-case:
|
||||
specifier: ^4.1.2
|
||||
version: 4.1.2
|
||||
cidr-tools:
|
||||
specifier: ^7.0.4
|
||||
version: 7.0.4
|
||||
colord:
|
||||
specifier: ^2.9.3
|
||||
version: 2.9.3
|
||||
|
@ -92,6 +95,21 @@ dependencies:
|
|||
ibantools:
|
||||
specifier: ^4.3.3
|
||||
version: 4.3.3
|
||||
ip-address:
|
||||
specifier: ^9.0.5
|
||||
version: 9.0.5
|
||||
ip-bigint:
|
||||
specifier: ^8.0.2
|
||||
version: 8.0.2
|
||||
ip-cidr:
|
||||
specifier: ^4.0.0
|
||||
version: 4.0.0
|
||||
is-cidr:
|
||||
specifier: ^5.0.3
|
||||
version: 5.0.3
|
||||
is-ip:
|
||||
specifier: ^5.0.1
|
||||
version: 5.0.1
|
||||
json5:
|
||||
specifier: ^2.2.3
|
||||
version: 2.2.3
|
||||
|
@ -4463,6 +4481,20 @@ packages:
|
|||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/cidr-regex@4.0.3:
|
||||
resolution: {integrity: sha512-HOwDIy/rhKeMf6uOzxtv7FAbrz8zPjmVKfSpM+U7/bNBXC5rtOyr758jxcptiSx6ZZn5LOhPJT5WWxPAGDV8dw==}
|
||||
engines: {node: '>=14'}
|
||||
dependencies:
|
||||
ip-regex: 5.0.0
|
||||
dev: false
|
||||
|
||||
/cidr-tools@7.0.4:
|
||||
resolution: {integrity: sha512-bKd6xC01ObuVKvJPGdV9Rz02KFO3mtHwMe/QTlcVuFAmU5n3RN/F3FgppHZaQjM+c/1i9YB9rgKNH/5iVqwCoA==}
|
||||
engines: {node: '>=18'}
|
||||
dependencies:
|
||||
ip-bigint: 8.0.2
|
||||
dev: false
|
||||
|
||||
/clean-regexp@1.0.0:
|
||||
resolution: {integrity: sha512-GfisEZEJvzKrmGWkvfhgzcz/BllN1USeqD2V6tg14OAOgaCD2Z/PUEuxnAZ/nPvmaHRG7a8y77p1T/IRQ4D1Hw==}
|
||||
engines: {node: '>=4'}
|
||||
|
@ -4490,6 +4522,13 @@ packages:
|
|||
wrap-ansi: 6.2.0
|
||||
dev: false
|
||||
|
||||
/clone-regexp@3.0.0:
|
||||
resolution: {integrity: sha512-ujdnoq2Kxb8s3ItNBtnYeXdm07FcU0u8ARAT1lQ2YdMwQC+cdiXX8KoqMVuglztILivceTtp4ivqGSmEmhBUJw==}
|
||||
engines: {node: '>=12'}
|
||||
dependencies:
|
||||
is-regexp: 3.1.0
|
||||
dev: false
|
||||
|
||||
/clone@1.0.4:
|
||||
resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==}
|
||||
engines: {node: '>=0.8'}
|
||||
|
@ -4594,6 +4633,11 @@ packages:
|
|||
upper-case: 2.0.2
|
||||
dev: false
|
||||
|
||||
/convert-hrtime@5.0.0:
|
||||
resolution: {integrity: sha512-lOETlkIeYSJWcbbcvjRKGxVMXJR+8+OQb/mTPbA4ObPMytYIsUbuOE0Jzy60hjARYszq1id0j8KgVhC+WGZVTg==}
|
||||
engines: {node: '>=12'}
|
||||
dev: false
|
||||
|
||||
/convert-source-map@1.9.0:
|
||||
resolution: {integrity: sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==}
|
||||
dev: true
|
||||
|
@ -5743,6 +5787,11 @@ packages:
|
|||
resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==}
|
||||
dev: true
|
||||
|
||||
/function-timeout@0.1.1:
|
||||
resolution: {integrity: sha512-0NVVC0TaP7dSTvn1yMiy6d6Q8gifzbvQafO46RtLG/kHJUBNd+pVRGOBoK44wNBvtSPUJRfdVvkFdD3p0xvyZg==}
|
||||
engines: {node: '>=14.16'}
|
||||
dev: false
|
||||
|
||||
/function.prototype.name@1.1.6:
|
||||
resolution: {integrity: sha512-Z5kx79swU5P27WEayXM1tBi5Ze/lbIyiNgU3qyXUOf9b2rgXYyF9Dy9Cx+IQv/Lc8WCG6L82zwUPpSS9hGehIg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
@ -6177,6 +6226,19 @@ packages:
|
|||
sprintf-js: 1.1.2
|
||||
dev: false
|
||||
|
||||
/ip-address@9.0.5:
|
||||
resolution: {integrity: sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==}
|
||||
engines: {node: '>= 12'}
|
||||
dependencies:
|
||||
jsbn: 1.1.0
|
||||
sprintf-js: 1.1.3
|
||||
dev: false
|
||||
|
||||
/ip-bigint@8.0.2:
|
||||
resolution: {integrity: sha512-UMKHGx7+4O2mD/6jnpNtt4UMA0tRQ3XAiNVYlbLssFU1LegKqKwPqbqtLVW7lQU/c6rCWI1hcxxs4TP96Xa+rQ==}
|
||||
engines: {node: '>=18'}
|
||||
dev: false
|
||||
|
||||
/ip-cidr@3.1.0:
|
||||
resolution: {integrity: sha512-HUCn4snshEX1P8cja/IyU3qk8FVDW8T5zZcegDFbu4w7NojmAhk5NcOgj3M8+0fmumo1afJTPDtJlzsxLdOjtg==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
|
@ -6185,6 +6247,18 @@ packages:
|
|||
jsbn: 1.1.0
|
||||
dev: false
|
||||
|
||||
/ip-cidr@4.0.0:
|
||||
resolution: {integrity: sha512-i1Jhb9sqm2+PuOHTfya3ekAUi+dadhgcEz+4FKKY1hXemocP4Xf7io8Xflc74/i2ejxe/5fp4z8z3BAsfAZ8sw==}
|
||||
engines: {node: '>=16.14.0'}
|
||||
dependencies:
|
||||
ip-address: 9.0.5
|
||||
dev: false
|
||||
|
||||
/ip-regex@5.0.0:
|
||||
resolution: {integrity: sha512-fOCG6lhoKKakwv+C6KdsOnGvgXnmgfmp0myi3bcNwj3qfwPAxRKWEuFhvEFF7ceYIz6+1jRZ+yguLFAmUNPEfw==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
dev: false
|
||||
|
||||
/is-alphabetical@1.0.4:
|
||||
resolution: {integrity: sha512-DwzsA04LQ10FHTZuL0/grVDk4rFoVH1pjAToYwBrHSxcrBIGQuXrQMtD5U1b0U2XVgKZCTLLP8u2Qxqhy3l2Vg==}
|
||||
dev: true
|
||||
|
@ -6240,6 +6314,13 @@ packages:
|
|||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/is-cidr@5.0.3:
|
||||
resolution: {integrity: sha512-lKkM0tmz07dAxNsr8Ii9MGreExa9ZR34N9j8mTG5op824kcwBqinZPowNjcVWWc7j+jR8XAMMItOmBkniN0jOA==}
|
||||
engines: {node: '>=14'}
|
||||
dependencies:
|
||||
cidr-regex: 4.0.3
|
||||
dev: false
|
||||
|
||||
/is-core-module@2.13.0:
|
||||
resolution: {integrity: sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==}
|
||||
dependencies:
|
||||
|
@ -6305,6 +6386,14 @@ packages:
|
|||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/is-ip@5.0.1:
|
||||
resolution: {integrity: sha512-FCsGHdlrOnZQcp0+XT5a+pYowf33itBalCl+7ovNXC/7o5BhIpG14M3OrpPPdBSIQJCm+0M5+9mO7S9VVTTCFw==}
|
||||
engines: {node: '>=14.16'}
|
||||
dependencies:
|
||||
ip-regex: 5.0.0
|
||||
super-regex: 0.2.0
|
||||
dev: false
|
||||
|
||||
/is-lower-case@1.1.3:
|
||||
resolution: {integrity: sha512-+5A1e/WJpLLXZEDlgz4G//WYSHyQBD32qa4Jd3Lw06qQlv3fJHnp3YIHjTQSGzHMgzmVKz2ZP3rBxTHkPw/lxA==}
|
||||
dependencies:
|
||||
|
@ -6370,6 +6459,11 @@ packages:
|
|||
engines: {node: '>=0.10.0'}
|
||||
dev: true
|
||||
|
||||
/is-regexp@3.1.0:
|
||||
resolution: {integrity: sha512-rbku49cWloU5bSMI+zaRaXdQHXnthP6DZ/vLnfdSKyL4zUzuWnomtOEiZZOd+ioQ+avFo/qau3KPTc7Fjy1uPA==}
|
||||
engines: {node: '>=12'}
|
||||
dev: false
|
||||
|
||||
/is-shared-array-buffer@1.0.2:
|
||||
resolution: {integrity: sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==}
|
||||
dependencies:
|
||||
|
@ -8183,6 +8277,10 @@ packages:
|
|||
resolution: {integrity: sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==}
|
||||
dev: false
|
||||
|
||||
/sprintf-js@1.1.3:
|
||||
resolution: {integrity: sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==}
|
||||
dev: false
|
||||
|
||||
/sql-formatter@13.0.0:
|
||||
resolution: {integrity: sha512-V21cVvge4rhn9Fa7K/fTKcmPM+x1yee6Vhq8ZwgaWh3VPBqApgsaoFB5kLAhiqRo5AmSaRyLU7LIdgnNwH01/w==}
|
||||
hasBin: true
|
||||
|
@ -8313,6 +8411,15 @@ packages:
|
|||
dependencies:
|
||||
acorn: 8.11.2
|
||||
|
||||
/super-regex@0.2.0:
|
||||
resolution: {integrity: sha512-WZzIx3rC1CvbMDloLsVw0lkZVKJWbrkJ0k1ghKFmcnPrW1+jWbgTkTEWVtD9lMdmI4jZEz40+naBxl1dCUhXXw==}
|
||||
engines: {node: '>=14.16'}
|
||||
dependencies:
|
||||
clone-regexp: 3.0.0
|
||||
function-timeout: 0.1.1
|
||||
time-span: 5.1.0
|
||||
dev: false
|
||||
|
||||
/supports-color@5.5.0:
|
||||
resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
|
||||
engines: {node: '>=4'}
|
||||
|
@ -8405,6 +8512,13 @@ packages:
|
|||
resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==}
|
||||
dev: true
|
||||
|
||||
/time-span@5.1.0:
|
||||
resolution: {integrity: sha512-75voc/9G4rDIJleOo4jPvN4/YC4GRZrY8yy1uU4lwrB3XEQbWve8zXoO5No4eFrGcTAMYyoY67p8jRQdtA1HbA==}
|
||||
engines: {node: '>=12'}
|
||||
dependencies:
|
||||
convert-hrtime: 5.0.0
|
||||
dev: false
|
||||
|
||||
/tiny-emitter@2.1.0:
|
||||
resolution: {integrity: sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==}
|
||||
dev: false
|
||||
|
|
|
@ -81,6 +81,7 @@ import { tool as uuidGenerator } from './uuid-generator';
|
|||
import { tool as macAddressLookup } from './mac-address-lookup';
|
||||
import { tool as xmlFormatter } from './xml-formatter';
|
||||
import { tool as yamlViewer } from './yaml-viewer';
|
||||
import { tool as ipRangeToCidr } from './ip-range-to-cidr';
|
||||
|
||||
export const toolsByCategory: ToolCategory[] = [
|
||||
{
|
||||
|
@ -152,7 +153,15 @@ export const toolsByCategory: ToolCategory[] = [
|
|||
},
|
||||
{
|
||||
name: 'Network',
|
||||
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
|
||||
components: [
|
||||
ipv4SubnetCalculator,
|
||||
ipv4AddressConverter,
|
||||
ipv4RangeExpander,
|
||||
ipRangeToCidr,
|
||||
macAddressLookup,
|
||||
macAddressGenerator,
|
||||
ipv6UlaGenerator,
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Math',
|
||||
|
|
12
src/tools/ip-range-to-cidr/index.ts
Normal file
12
src/tools/ip-range-to-cidr/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { Binary } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'IPv4/6 Range to CIDR(s) Calculator',
|
||||
path: '/ip-range-to-cidr',
|
||||
description: 'Calculate CIDR(s) from an IP Range (IPv4/6)',
|
||||
keywords: ['ip', 'range', 'to', 'cidr'],
|
||||
component: () => import('./ip-range-to-cidr.vue'),
|
||||
icon: Binary,
|
||||
createdAt: new Date('2024-01-10'),
|
||||
});
|
17
src/tools/ip-range-to-cidr/ip-bigint.d.ts
vendored
Normal file
17
src/tools/ip-range-to-cidr/ip-bigint.d.ts
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
declare module 'ip-bigint' {
|
||||
type IPInfo = {
|
||||
number: bigint;
|
||||
version: number;
|
||||
ipv4mapped?: boolean;
|
||||
scopeid?:string;
|
||||
};
|
||||
type StringifyOptions = {
|
||||
compress?:boolean;
|
||||
hexify?:boolean;
|
||||
};
|
||||
|
||||
export function normalizeIp(ip: string, options: StringifyOptions = {compress = true, hexify = false} = {})
|
||||
export function stringifyIp(ip: IPInfo, options: StringifyOptions = {compress = true, hexify = false}): string;
|
||||
export function ipVersion(ip: string): number;
|
||||
export function parseIp(ip): IPInfo;
|
||||
}
|
117
src/tools/ip-range-to-cidr/ip-range-to-cidr.vue
Normal file
117
src/tools/ip-range-to-cidr/ip-range-to-cidr.vue
Normal file
|
@ -0,0 +1,117 @@
|
|||
<script setup lang="ts">
|
||||
import { merge, parse } from 'cidr-tools';
|
||||
import { isIP, isIPv6 } from 'is-ip';
|
||||
import { Exchange } from '@vicons/tabler';
|
||||
import { stringifyIp } from 'ip-bigint';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const rawStartAddress = useStorage('ip-range-to-cidr:startAddress', '192.168.1.1');
|
||||
const rawEndAddress = useStorage('ip-range-to-cidr:endAddress', '192.168.6.255');
|
||||
|
||||
const isReversed = ref<boolean>(false);
|
||||
const isNotSameVersion = ref<boolean>(false);
|
||||
|
||||
const result = computed(() => {
|
||||
try {
|
||||
isNotSameVersion.value = isIPv6(rawEndAddress.value) !== isIPv6(rawStartAddress.value);
|
||||
isReversed.value = false;
|
||||
if (isNotSameVersion.value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const startIp = parse(rawStartAddress.value).start;
|
||||
const endIp = parse(rawEndAddress.value).end;
|
||||
isReversed.value = startIp > endIp;
|
||||
if (isReversed.value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const version = isIPv6(rawStartAddress.value) ? 6 : 4;
|
||||
const ipRangeLength = endIp - startIp + 1n;
|
||||
const allIps = new BigInt64Array(Number(ipRangeLength));
|
||||
let iterIp = startIp;
|
||||
for (let i = 0; i < ipRangeLength; i++) {
|
||||
allIps[i] = iterIp++;
|
||||
}
|
||||
|
||||
return merge(Array.from(allIps, ip => stringifyIp({ number: ip, version })));
|
||||
}
|
||||
catch (e) {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
const startIpValidation = useValidation({
|
||||
source: rawStartAddress,
|
||||
rules: [{ message: 'Invalid ipv4/6 address', validator: ip => isIP(ip) }],
|
||||
});
|
||||
const endIpValidation = useValidation({
|
||||
source: rawEndAddress,
|
||||
rules: [{ message: 'Invalid ipv4/6 address', validator: ip => isIP(ip) }],
|
||||
});
|
||||
|
||||
const showResult = computed(() => endIpValidation.isValid && startIpValidation.isValid && result.value.length > 0);
|
||||
|
||||
function onSwitchStartEndClicked() {
|
||||
const tmpStart = rawStartAddress.value;
|
||||
rawStartAddress.value = rawEndAddress.value;
|
||||
rawEndAddress.value = tmpStart;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-grid cols="4" x-gap="12" mb-6 w-full>
|
||||
<n-gi span="2">
|
||||
<c-input-text
|
||||
v-model:value="rawStartAddress"
|
||||
label="Start address"
|
||||
placeholder="Start IPv4/6 address..."
|
||||
:validation="startIpValidation"
|
||||
clearable
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi span="2">
|
||||
<c-input-text
|
||||
v-model:value="rawEndAddress"
|
||||
label="End address"
|
||||
placeholder="End IPv4/6 address..."
|
||||
:validation="endIpValidation"
|
||||
clearable
|
||||
/>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
|
||||
<c-card v-if="showResult" title="CIDR" data-test-id="result">
|
||||
<ul style="list-item-type: none">
|
||||
<li v-for="cidr in result" :key="cidr">
|
||||
{{ cidr }}
|
||||
</li>
|
||||
</ul>
|
||||
</c-card>
|
||||
<n-alert
|
||||
v-else-if="startIpValidation.isValid && endIpValidation.isValid && isReversed"
|
||||
title="Invalid combination of start and end IPv4/6 address"
|
||||
type="error"
|
||||
>
|
||||
<div my-3 op-70>
|
||||
The end IPv4/6 address is lower than the start IPv4/6 address. This is not valid and no result could be calculated.
|
||||
In the most cases the solution to solve this problem is to change start and end address.
|
||||
</div>
|
||||
|
||||
<c-button @click="onSwitchStartEndClicked">
|
||||
<n-icon mr-2 :component="Exchange" depth="3" size="22" />
|
||||
Switch start and end IPv4/6 address
|
||||
</c-button>
|
||||
</n-alert>
|
||||
<n-alert
|
||||
v-else-if="isNotSameVersion"
|
||||
title="Invalid combination of IP version 4/6"
|
||||
type="error"
|
||||
>
|
||||
<div my-3 op-70>
|
||||
Start IP and End IP must be of same version: IPv4 or IPv6
|
||||
</div>
|
||||
</n-alert>
|
||||
</div>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue