aboutsummaryrefslogtreecommitdiff
path: root/src/tools/mac-address-lookup/mac-address-lookup.vue
blob: f3d9cd5992034a580faba7bde35de839d68fdb60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<template>
  <div>
    <n-form-item label="MAC address:" v-bind="validationAttrs">
      <n-input
        v-model:value="macAddress"
        size="large"
        placeholder="Type a MAC address"
        clearable
        autocomplete="off"
        autocorrect="off"
        autocapitalize="off"
        spellcheck="false"
      />
    </n-form-item>

    <n-form-item label="Vendor info:">
      <n-card>
        <n-text v-if="details">
          <div v-for="(detail, index) of details.split('\n')" :key="index">{{ detail }}</div>
        </n-text>

        <n-text v-else depth="3" italic>Unknown vendor for this address</n-text>
      </n-card>
    </n-form-item>

    <n-space justify="center">
      <c-button :disabled="!details" @click="copy"> Copy vendor info </c-button>
    </n-space>
  </div>
</template>

<script setup lang="ts">
import db from 'oui/oui.json';
import { macAddressValidation } from '@/utils/macAddress';
import { useCopy } from '@/composable/copy';

const getVendorValue = (address: string) => address.trim().replace(/[.:-]/g, '').toUpperCase().substring(0, 6);

const macAddress = ref('20:37:06:12:34:56');
const details = computed<string | undefined>(() => db[getVendorValue(macAddress.value)]);

const { attrs: validationAttrs } = macAddressValidation(macAddress);

const { copy } = useCopy({ source: details, text: 'Vendor info copied to the clipboard' });
</script>

<style lang="less" scoped></style>