Compare commits

...

10 Commits

Author SHA1 Message Date
sharevb
e5a30039fb
Merge c45a055643 into b430baef40 2024-06-16 11:57:41 +00:00
ShareVB
c45a055643 fix: nosonar in unit tests 2024-06-16 13:57:24 +02:00
ShareVB
11206a52a1 fix(Mac Address Converter): update description 2024-06-16 13:57:07 +02:00
ShareVB
068d79a08f chore: fix strange corepack message
Fix corepack claiming strange thing : UsageError: This project is configured to use yarn because /home/runner/work/it-tools/it-tools/package.json has a "packageManager" field
2024-06-16 13:53:12 +02:00
ShareVB
df049e2e69 Merge branch 'feat/mac-address-converter' of https://github.com/sharevb/it-tools into feat/mac-address-converter 2024-06-16 13:51:56 +02:00
ShareVB
743757761d feat(MAC Address Converter): add EUI-64 and IPv6 support
Fix #1146
2024-06-16 13:50:56 +02:00
sharevb
12b0dc100d
Merge branch 'main' into feat/mac-address-converter 2024-05-15 22:28:00 +02:00
ShareVB
d14371c5c2 fix: refactor with unit test 2024-05-15 22:09:37 +02:00
sharevb
00b85de1a0
Merge branch 'main' into feat/mac-address-converter 2024-02-04 14:17:02 +01:00
ShareVB
4598ebae09 feat(new tool): MAC Address Converter 2024-02-03 14:06:32 +01:00
7 changed files with 223 additions and 4 deletions

1
components.d.ts vendored
View File

@ -117,6 +117,7 @@ declare module '@vue/runtime-core' {
ListConverter: typeof import('./src/tools/list-converter/list-converter.vue')['default']
LocaleSelector: typeof import('./src/modules/i18n/components/locale-selector.vue')['default']
LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default']
MacAddressConverter: typeof import('./src/tools/mac-address-converter/mac-address-converter.vue')['default']
MacAddressGenerator: typeof import('./src/tools/mac-address-generator/mac-address-generator.vue')['default']
MacAddressLookup: typeof import('./src/tools/mac-address-lookup/mac-address-lookup.vue')['default']
MathEvaluator: typeof import('./src/tools/math-evaluator/math-evaluator.vue')['default']

View File

@ -138,5 +138,6 @@
"vitest": "^0.34.0",
"workbox-window": "^7.0.0",
"zx": "^7.2.1"
}
},
"packageManager": "pnpm@8.15.3"
}

View File

@ -1,9 +1,8 @@
import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as macAddressConverter } from './mac-address-converter';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
@ -152,7 +151,15 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
ipv4RangeExpander,
macAddressLookup,
macAddressGenerator,
macAddressConverter,
ipv6UlaGenerator,
],
},
{
name: 'Math',

View File

@ -0,0 +1,20 @@
import { Devices } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'MAC Address Converter',
path: '/mac-address-converter',
description: 'Change the format of a MAC address and chose between different formats (EUI-48, EUI-64, IPv6)',
keywords: [
'converter',
'mac',
'address',
'format',
'link-local',
'ipv6',
'eui-48',
'eui-64',
],
component: () => import('./mac-address-converter.vue'),
icon: Devices,
});

View File

@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import {
convertMacCISCO, convertMacCanonical,
convertMacCanonicalIEEE, convertMacCanonicalIETF,
convertMacToEUI64CISCO, convertMacToEUI64CanonicalIEEE,
convertMacToEUI64CanonicalIETF, convertMacToLinkLocalIPv6,
convertMacToNumber,
} from './mac-address-converter.service';
describe('mac-address-converter', () => {
it('Convert MAC Address to given format', async () => {
expect(convertMacCanonical('')).to.equal('');
const macValue = '00:0a:95:9d:68:16';
expect(convertMacCanonicalIETF(macValue)).to.equal('00:0a:95:9d:68:16');
expect(convertMacCanonical(macValue)).to.equal('00.0a.95.9d.68.16');
expect(convertMacCanonicalIEEE(macValue)).to.equal('00-0A-95-9D-68-16');
expect(convertMacCISCO(macValue)).to.equal('000a.959d.6816');
expect(convertMacToEUI64CanonicalIETF(macValue, true)).to.equal('02:0a:95:ff:fe:9d:68:16'); // NOSONAR
expect(convertMacToEUI64CanonicalIETF(macValue, false)).to.equal('00:0a:95:ff:fe:9d:68:16'); // NOSONAR
expect(convertMacToEUI64CanonicalIEEE(macValue, true)).to.equal('02-0A-95-FF-FE-9D-68-16');
expect(convertMacToEUI64CanonicalIEEE(macValue, false)).to.equal('00-0A-95-FF-FE-9D-68-16');
expect(convertMacToEUI64CISCO(macValue, true)).to.equal('020a.95ff.fe9d.6816');
expect(convertMacToEUI64CISCO(macValue, false)).to.equal('000a.95ff.fe9d.6816');
expect(convertMacToNumber(macValue)).to.equal(45459793942);
expect(convertMacToLinkLocalIPv6(macValue)).to.equal(':fe80::20a:95ff:fe9d:6816');
});
});

View File

@ -0,0 +1,59 @@
function convertMac(mac: string, group: number = 2, char: string = ':'): string {
mac = mac.replace(/[\W_]+/g, '');
return mac.match(new RegExp(`.{1,${group}}`, 'g'))?.join(char) || '';
}
function convertMacToEUI64(mac: string, ipv6: boolean) {
const macIETF = convertMac(mac);
// Split the MAC address into an array of hex values
const macArray = macIETF.split(':').map(hex => Number.parseInt(hex, 16));
// For IPv6, invert the 7th bit of the first byte
if (ipv6) {
macArray[0] ^= 0x02;
}
// Insert FFFE in the middle
const eui64Array = [
macArray[0], macArray[1], macArray[2],
0xFF, 0xFE,
macArray[3], macArray[4], macArray[5],
];
// Convert the array to a colon-separated string
const eui64 = eui64Array.map(byte => byte.toString(16).padStart(2, '0')).join(':');
// Group into IPv6 EUI-64 format (XXXX:XXFF:FEXX:XXXX)
return eui64.replace(/:/g, '').match(/.{1,4}/g)!.join(':');
}
export function convertMacToEUI64CanonicalIETF(mac: string, ipv6: boolean) {
return convertMac(convertMacToEUI64(mac, ipv6).toLocaleLowerCase());
}
export function convertMacToEUI64CanonicalIEEE(mac: string, ipv6: boolean) {
return convertMac(convertMacToEUI64(mac, ipv6).toLocaleUpperCase(), 2, '-');
}
export function convertMacToEUI64CISCO(mac: string, ipv6: boolean) {
return convertMac(convertMacToEUI64(mac, ipv6).toLocaleLowerCase(), 4, '.');
}
export function convertMacToLinkLocalIPv6(mac: string) {
return `:fe80::${convertMac(convertMacToEUI64(mac, true).toLocaleLowerCase(), 4, ':').replace(/^0/g, '')}`;
}
export function convertMacToNumber(mac: string) {
mac = mac.replace(/[\W_]+/g, '');
return Number.parseInt(mac, 16);
}
export function convertMacCanonicalIETF(mac: string): string {
return convertMac(mac.toLocaleLowerCase());
};
export function convertMacCanonical(mac: string): string {
return convertMac(mac, 2, '.');
};
export function convertMacCanonicalIEEE(mac: string): string {
return convertMac(mac.toLocaleUpperCase(), 2, '-');
};
export function convertMacCISCO(mac: string): string {
return convertMac(mac.toLocaleLowerCase(), 4, '.');
};

View File

@ -0,0 +1,101 @@
<script setup lang="ts">
import InputCopyable from '../../components/InputCopyable.vue';
import {
convertMacCISCO, convertMacCanonical,
convertMacCanonicalIEEE, convertMacCanonicalIETF,
convertMacToEUI64CISCO, convertMacToEUI64CanonicalIEEE,
convertMacToEUI64CanonicalIETF, convertMacToLinkLocalIPv6,
convertMacToNumber,
} from './mac-address-converter.service';
const input = ref('AA:BB:CC:DD:EE:FF');
const formats = computed(() => [
{
label: 'Canonical IETF Format:',
value: convertMacCanonicalIETF(input.value),
},
{
label: 'Canonical Format:',
value: convertMacCanonical(input.value),
},
{
label: 'Canonical IEEE Format:',
value: convertMacCanonicalIEEE(input.value),
},
{
label: 'Cisco:',
value: convertMacCISCO(input.value),
},
{
label: 'Hex:',
value: convertMacToNumber(input.value).toString(16),
},
{
label: 'Decimal:',
value: convertMacToNumber(input.value).toString(10),
},
{
label: 'EUI-64 Canonical IETF Format:',
value: convertMacToEUI64CanonicalIETF(input.value, false),
},
{
label: 'EUI-64 Canonical IEEE Format:',
value: convertMacToEUI64CanonicalIEEE(input.value, false),
},
{
label: 'EUI-64 Cisco:',
value: convertMacToEUI64CISCO(input.value, false),
},
{
label: 'EUI-64 IPv6 Canonical IETF Format:',
value: convertMacToEUI64CanonicalIETF(input.value, true),
},
{
label: 'EUI-64 IPv6 Canonical IEEE Format:',
value: convertMacToEUI64CanonicalIEEE(input.value, true),
},
{
label: 'EUI-64 IPv6 Cisco:',
value: convertMacToEUI64CISCO(input.value, true),
},
{
label: 'Link-Local IPv6:',
value: convertMacToLinkLocalIPv6(input.value),
},
]);
const inputLabelAlignmentConfig = {
labelPosition: 'left',
labelWidth: '120px',
labelAlign: 'right',
};
</script>
<template>
<c-card>
<c-input-text
v-model:value="input"
label="MAC address:"
size="large"
placeholder="Type a MAC address"
clearable
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
mb-5
/>
<div my-16px divider />
<InputCopyable
v-for="format in formats"
:key="format.label"
:value="format.value"
:label="format.label"
v-bind="inputLabelAlignmentConfig"
mb-1
/>
</c-card>
</template>