Skip to content

Commit

Permalink
feat(new tool): DNS query (over HTTPS)
Browse files Browse the repository at this point in the history
Fix part of CorentinTh#831
  • Loading branch information
sharevb committed Oct 26, 2024
1 parent 80e46c9 commit 2df9373
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
68 changes: 68 additions & 0 deletions src/tools/dns-queries/dns-queries.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<script setup lang="ts">
import { combineTXT, query, wellknown } from 'dns-query';
import types from './dns.records.types.json';
const type = ref('A');
const name = ref('google.com');
const answers = ref<string[]>([]);
async function queryDNS() {
const endpoints = await wellknown.endpoints('doh');
try {
const response = await query({
question: { type: type.value, name: name.value },
}, {
endpoints,
});
if (type.value === 'TXT') {
answers.value = (response.answers || []).map(answer => `${answer.name} ${answer.type} ${combineTXT(answer.data as Uint8Array[])} (TTL=${answer.ttl})`);
}
else {
answers.value = (response.answers || []).map(answer => `${answer.name} ${answer.type} ${answer.data} (TTL=${answer.ttl})`);
}
}
catch (error: any) {
answers.value = [error.toString()];
}
}
</script>

<template>
<div>
<c-input-text
v-model:value="name"
label="Name"
label-position="left"
placeholder="Name to query"
mb-2
/>
<c-select
v-model:value="type"
searchable
label="DNS record type:"
label-position="left"
:options="Object.values(types).map(kv => ({ value: kv.value, label: `${kv.value}: ${kv.label}` }))"
mb-2
/>

<div flex justify-center>
<c-button
@click="queryDNS"
>
Send DNS query
</c-button>
</div>

<n-divider />

<c-card title="Query results">
<textarea-copyable
v-for="(answer, index) in answers"
:key="index"
:value="answer"
word-wrap
mb-2
/>
</c-card>
</div>
</template>
49 changes: 49 additions & 0 deletions src/tools/dns-queries/dns.records.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[
{ "value": "A", "label": "Address record" },
{ "value": "AAAA", "label": "IPv6 address record" },
{ "value": "AFSDB", "label": "AFS database record" },
{ "value": "APL", "label": "Address Prefix List" },
{ "value": "CAA", "label": "Certification Authority Authorization" },
{ "value": "CDNSKEY", "label": "CDNSKEY" },
{ "value": "CDS", "label": "Child DS" },
{ "value": "CERT", "label": "Certificate record" },
{ "value": "CNAME", "label": "Canonical name record" },
{ "value": "CSYNC", "label": "Child-to-Parent Synchronization" },
{ "value": "DHCID", "label": "DHCP identifier" },
{ "value": "DLV", "label": "DNSSEC Lookaside Validation record" },
{ "value": "DNAME", "label": "Delegation name record" },
{ "value": "DNSKEY", "label": "DNS Key record" },
{ "value": "DS", "label": "Delegation signer" },
{ "value": "EUI48", "label": "MAC address (EUI-48)" },
{ "value": "EUI64", "label": "MAC address (EUI-64)" },
{ "value": "HINFO", "label": "Host Information" },
{ "value": "HIP", "label": "Host Identity Protocol" },
{ "value": "HTTPS", "label": "HTTPS Binding" },
{ "value": "IPSECKEY", "label": "IPsec Key" },
{ "value": "KEY", "label": "Key record" },
{ "value": "KX", "label": "Key Exchanger record" },
{ "value": "LOC", "label": "Location record" },
{ "value": "MX", "label": "Mail exchange record" },
{ "value": "NAPTR", "label": "Naming Authority Pointer" },
{ "value": "NS", "label": "Name server record" },
{ "value": "NSEC", "label": "Next Secure record" },
{ "value": "NSEC3", "label": "Next Secure record version 3" },
{ "value": "NSEC3PARAM", "label": "NSEC3 parameters" },
{ "value": "OPENPGPKEY", "label": "OpenPGP public key record" },
{ "value": "PTR", "label": "PTR Resource Record" },
{ "value": "RP", "label": "Responsible Person" },
{ "value": "RRSIG", "label": "DNSSEC signature" },
{ "value": "SIG", "label": "Signature" },
{ "value": "SMIMEA", "label": "S/MIME cert association" },
{ "value": "SOA", "label": "Start of [a zone of] authority record" },
{ "value": "SRV", "label": "Service locator" },
{ "value": "SSHFP", "label": "SSH Public Key Fingerprint" },
{ "value": "SVCB", "label": "Service Binding" },
{ "value": "TA", "label": "DNSSEC Trust Authorities" },
{ "value": "TKEY", "label": "Transaction Key record" },
{ "value": "TLSA", "label": "TLSA certificate association" },
{ "value": "TSIG", "label": "Transaction Signature" },
{ "value": "TXT", "label": "Text record" },
{ "value": "URI", "label": "Uniform Resource Identifier" },
{ "value": "ZONEMD", "label": "Message Digests for DNS Zones" }
]
12 changes: 12 additions & 0 deletions src/tools/dns-queries/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { World } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'DNS Queries',
path: '/dns-queries',
description: 'Perform DNS Queries (over HTTPS)',
keywords: ['dns', 'nslookup', 'queries'],
component: () => import('./dns-queries.vue'),
icon: World,
createdAt: new Date('2024-08-15'),
});
11 changes: 10 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 dnsQueries } from './dns-queries';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
Expand Down Expand Up @@ -143,7 +144,15 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
ipv4RangeExpander,
macAddressLookup,
macAddressGenerator,
ipv6UlaGenerator,
dnsQueries,
],
},
{
name: 'Math',
Expand Down

0 comments on commit 2df9373

Please sign in to comment.