mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 21:44:40 +03:00
feat(new tool): DNS/RDAP queries
Co-authored-by: @stevenlee87
This commit is contained in:
1 parent
45ed4a7aed
commit
37cc92faf9
3 files changed
+412
No files matched your search
@@ -0,0 +1,166 @@
|
|||||||
|
export const defaultRecordTypes = ['A', 'AAAA', 'CNAME', 'MX', 'TXT', 'NS', 'SOA'] as const;
|
||||||
|
|
||||||
|
export const allRecordTypes = ['A', 'AAAA', 'CNAME', 'MX', 'TXT', 'NS', 'SOA', 'SRV', 'CAA', 'PTR'] as const;
|
||||||
|
|
||||||
|
export type DnsRecordType = typeof allRecordTypes[number];
|
||||||
|
|
||||||
|
const dnsTypeNumberToName: Record<number, string> = {
|
||||||
|
1: 'A',
|
||||||
|
2: 'NS',
|
||||||
|
5: 'CNAME',
|
||||||
|
6: 'SOA',
|
||||||
|
12: 'PTR',
|
||||||
|
15: 'MX',
|
||||||
|
16: 'TXT',
|
||||||
|
28: 'AAAA',
|
||||||
|
33: 'SRV',
|
||||||
|
257: 'CAA',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getTypeName(typeNumber: number): string {
|
||||||
|
return dnsTypeNumberToName[typeNumber] ?? `TYPE${typeNumber}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DnsAnswer {
|
||||||
|
name: string
|
||||||
|
type: number
|
||||||
|
TTL: number
|
||||||
|
data: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DnsResponse {
|
||||||
|
Status: number
|
||||||
|
TC: boolean
|
||||||
|
RD: boolean
|
||||||
|
RA: boolean
|
||||||
|
AD: boolean
|
||||||
|
CD: boolean
|
||||||
|
Question: { name: string; type: number }[]
|
||||||
|
Answer?: DnsAnswer[]
|
||||||
|
Authority?: DnsAnswer[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function queryDns({ domain, type }: { domain: string; type: string }): Promise<DnsResponse> {
|
||||||
|
const url = `https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=${encodeURIComponent(type)}`;
|
||||||
|
|
||||||
|
const response = await fetch(url, {
|
||||||
|
headers: { Accept: 'application/dns-json' },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`DNS query failed: ${response.status} ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function queryAllDns(domain: string, types: readonly string[]): Promise<DnsAnswer[]> {
|
||||||
|
const results = await Promise.allSettled(
|
||||||
|
types.map(type => queryDns({ domain, type })),
|
||||||
|
);
|
||||||
|
|
||||||
|
const seen = new Set<string>();
|
||||||
|
const answers: DnsAnswer[] = [];
|
||||||
|
for (const result of results) {
|
||||||
|
if (result.status === 'fulfilled' && result.value.Answer) {
|
||||||
|
for (const answer of result.value.Answer) {
|
||||||
|
const key = `${answer.type}|${answer.name}|${answer.data}`;
|
||||||
|
if (!seen.has(key)) {
|
||||||
|
seen.add(key);
|
||||||
|
answers.push(answer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return answers;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDnsRecords(answers: DnsAnswer[]): string {
|
||||||
|
if (answers.length === 0) {
|
||||||
|
return 'No records found';
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines = answers.map((answer) => {
|
||||||
|
const typeName = getTypeName(answer.type);
|
||||||
|
return `${typeName}\t${answer.name}\t${answer.TTL}s\t${answer.data}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WhoisInfo {
|
||||||
|
domainName: string
|
||||||
|
registrar: string
|
||||||
|
registrationDate: string
|
||||||
|
expirationDate: string
|
||||||
|
updatedDate: string
|
||||||
|
status: string[]
|
||||||
|
nameServers: string[]
|
||||||
|
dnssec: string
|
||||||
|
registrantCountry: string
|
||||||
|
registrantProvince: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function queryWhois(domain: string): Promise<WhoisInfo | null> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`https://rdap.org/domain/${encodeURIComponent(domain)}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
return parseRdapResponse(data, domain);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseRdapResponse(data: any, domain: string): WhoisInfo {
|
||||||
|
const events = data.events ?? [];
|
||||||
|
const findEvent = (action: string) => {
|
||||||
|
const ev = events.find((e: any) => e.eventAction === action);
|
||||||
|
return ev?.eventDate ? formatDate(ev.eventDate) : '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const registrarEntity = (data.entities ?? []).find((e: any) => e.roles?.includes('registrar'));
|
||||||
|
const registrar = registrarEntity?.vcardArray?.[1]
|
||||||
|
?.find((v: any) => v[0] === 'fn')?.[3] ?? '';
|
||||||
|
|
||||||
|
const registrantEntity = (data.entities ?? []).find((e: any) => e.roles?.includes('registrant'));
|
||||||
|
const registrantVcard = registrantEntity?.vcardArray?.[1] ?? [];
|
||||||
|
const adr = registrantVcard.find((v: any) => v[0] === 'adr');
|
||||||
|
const registrantCountry = adr?.[1]?.cc ?? '';
|
||||||
|
const registrantProvince = adr?.[3]?.[4] ?? '';
|
||||||
|
|
||||||
|
const nameServers = (data.nameservers ?? [])
|
||||||
|
.map((ns: any) => (ns.ldhName ?? '').replace(/\.$/, ''))
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
const status = (data.status ?? []).map((s: string) => s.replaceAll(' ', ''));
|
||||||
|
|
||||||
|
const dnssec = data.secureDNS?.delegationSigned ? 'signed' : 'unsigned';
|
||||||
|
|
||||||
|
return {
|
||||||
|
domainName: data.ldhName ?? domain,
|
||||||
|
registrar,
|
||||||
|
registrationDate: findEvent('registration'),
|
||||||
|
expirationDate: findEvent('expiration'),
|
||||||
|
updatedDate: findEvent('last changed'),
|
||||||
|
status,
|
||||||
|
nameServers,
|
||||||
|
dnssec,
|
||||||
|
registrantCountry,
|
||||||
|
registrantProvince,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(isoDate: string): string {
|
||||||
|
try {
|
||||||
|
const d = new Date(isoDate);
|
||||||
|
return `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, '0')}-${String(d.getUTCDate()).padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return isoDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useCopy } from '@/composable/copy';
|
||||||
|
import { queryAllDns, queryWhois, formatDnsRecords, getTypeName, defaultRecordTypes } from './dns-query.service';
|
||||||
|
import type { DnsAnswer, WhoisInfo } from './dns-query.service';
|
||||||
|
|
||||||
|
const domain = ref('example.com');
|
||||||
|
const isLoading = ref(false);
|
||||||
|
const errorMessage = ref('');
|
||||||
|
const answers = ref<DnsAnswer[]>([]);
|
||||||
|
const whoisInfo = ref<WhoisInfo | null>(null);
|
||||||
|
const whoisLoading = ref(false);
|
||||||
|
const hasQueried = ref(false);
|
||||||
|
|
||||||
|
const domainValidationRules = [
|
||||||
|
{
|
||||||
|
message: 'Please enter a valid domain name',
|
||||||
|
validator: (value: string) => /^([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/.test(value.trim()),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const groupedAnswers = computed(() => {
|
||||||
|
const groups: { type: string; records: DnsAnswer[] }[] = [];
|
||||||
|
const seen = new Map<string, DnsAnswer[]>();
|
||||||
|
|
||||||
|
for (const answer of answers.value) {
|
||||||
|
const typeName = getTypeName(answer.type);
|
||||||
|
if (!seen.has(typeName)) {
|
||||||
|
const records: DnsAnswer[] = [];
|
||||||
|
seen.set(typeName, records);
|
||||||
|
groups.push({ type: typeName, records });
|
||||||
|
}
|
||||||
|
seen.get(typeName)!.push(answer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return groups;
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedResult = computed(() => formatDnsRecords(answers.value));
|
||||||
|
|
||||||
|
const { copy } = useCopy({ source: formattedResult, text: 'DNS records copied to the clipboard' });
|
||||||
|
|
||||||
|
async function doQuery() {
|
||||||
|
const trimmed = domain.value.trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoading.value = true;
|
||||||
|
errorMessage.value = '';
|
||||||
|
answers.value = [];
|
||||||
|
whoisInfo.value = null;
|
||||||
|
hasQueried.value = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
answers.value = await queryAllDns(trimmed, defaultRecordTypes);
|
||||||
|
}
|
||||||
|
catch (err: unknown) {
|
||||||
|
errorMessage.value = err instanceof Error ? err.message : 'DNS query failed';
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
whoisLoading.value = true;
|
||||||
|
try {
|
||||||
|
whoisInfo.value = await queryWhois(trimmed);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// WHOIS is best-effort
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
whoisLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="domain"
|
||||||
|
label="Domain name"
|
||||||
|
placeholder="e.g. example.com"
|
||||||
|
clearable
|
||||||
|
autocomplete="off"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="off"
|
||||||
|
spellcheck="false"
|
||||||
|
:validation-rules="domainValidationRules"
|
||||||
|
mb-4
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div flex justify-center mb-4>
|
||||||
|
<c-button :disabled="!domain.trim() || isLoading" @click="doQuery()">
|
||||||
|
{{ isLoading ? 'Querying...' : 'Query DNS' }}
|
||||||
|
</c-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<n-alert v-if="errorMessage" type="error" mb-4>
|
||||||
|
{{ errorMessage }}
|
||||||
|
</n-alert>
|
||||||
|
|
||||||
|
<div v-if="hasQueried && !isLoading && !errorMessage">
|
||||||
|
<div v-if="groupedAnswers.length > 0">
|
||||||
|
<div v-for="group in groupedAnswers" :key="group.type" mb-4>
|
||||||
|
<div mb-2 font-bold text-15px>
|
||||||
|
{{ group.type }}
|
||||||
|
</div>
|
||||||
|
<n-table :bordered="true" :single-line="false" size="small">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">TTL</th>
|
||||||
|
<th scope="col">Data</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="(answer, index) in group.records" :key="index">
|
||||||
|
<td>{{ answer.name }}</td>
|
||||||
|
<td>{{ answer.TTL }}s</td>
|
||||||
|
<td style="word-break: break-all;">
|
||||||
|
{{ answer.data }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</n-table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div flex justify-center mb-5>
|
||||||
|
<c-button @click="copy()">
|
||||||
|
Copy results
|
||||||
|
</c-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<c-card v-else mb-4>
|
||||||
|
<div italic op-60>
|
||||||
|
No records found for this domain.
|
||||||
|
</div>
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="whoisLoading" mt-2 op-60 italic>
|
||||||
|
Loading WHOIS info...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="whoisInfo" mt-2>
|
||||||
|
<n-divider />
|
||||||
|
<div mb-3 font-bold text-16px>
|
||||||
|
WHOIS
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<n-table :bordered="true" :single-line="false" size="small">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td font-500 w-180px>
|
||||||
|
Domain Name
|
||||||
|
</td>
|
||||||
|
<td>{{ whoisInfo.domainName }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.registrar">
|
||||||
|
<td font-500>
|
||||||
|
Registrar
|
||||||
|
</td>
|
||||||
|
<td>{{ whoisInfo.registrar }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.registrationDate">
|
||||||
|
<td font-500>
|
||||||
|
Registration Date
|
||||||
|
</td>
|
||||||
|
<td>{{ whoisInfo.registrationDate }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.expirationDate">
|
||||||
|
<td font-500>
|
||||||
|
Expiration Date
|
||||||
|
</td>
|
||||||
|
<td>{{ whoisInfo.expirationDate }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.updatedDate">
|
||||||
|
<td font-500>
|
||||||
|
Updated Date
|
||||||
|
</td>
|
||||||
|
<td>{{ whoisInfo.updatedDate }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.registrantCountry">
|
||||||
|
<td font-500>
|
||||||
|
Registrant
|
||||||
|
</td>
|
||||||
|
<td>{{ [whoisInfo.registrantProvince, whoisInfo.registrantCountry].filter(Boolean).join(', ') }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.nameServers.length > 0">
|
||||||
|
<td font-500>
|
||||||
|
Name Servers
|
||||||
|
</td>
|
||||||
|
<td>{{ whoisInfo.nameServers.join(', ') }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.status.length > 0">
|
||||||
|
<td font-500>
|
||||||
|
Domain Status
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div v-for="s in whoisInfo.status" :key="s">
|
||||||
|
{{ s }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="whoisInfo.dnssec">
|
||||||
|
<td font-500>
|
||||||
|
DNSSEC
|
||||||
|
</td>
|
||||||
|
<td>{{ whoisInfo.dnssec }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</n-table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Cloudflare DNS/RDAP Queries',
|
||||||
|
path: '/dns-query',
|
||||||
|
description: 'Query DNS records and RDAP for any domain name online using Cloudflare DNS/RDAP.org.',
|
||||||
|
keywords: [
|
||||||
|
'dns',
|
||||||
|
'query',
|
||||||
|
'lookup',
|
||||||
|
'resolve',
|
||||||
|
'domain',
|
||||||
|
'A',
|
||||||
|
'AAAA',
|
||||||
|
'CNAME',
|
||||||
|
'MX',
|
||||||
|
'TXT',
|
||||||
|
'NS',
|
||||||
|
'SOA',
|
||||||
|
'network',
|
||||||
|
'devops',
|
||||||
|
'rdap',
|
||||||
|
],
|
||||||
|
component: () => import('./dns-query.vue'),
|
||||||
|
icon: defineAsyncComponent(() => import('@vicons/tabler/es/World')),
|
||||||
|
createdAt: new Date('2026-07-11'),
|
||||||
|
category: 'Network',
|
||||||
|
externAccessDescription:
|
||||||
|
"This tool resolves DNS records for a given domain using Cloudflare's DNS over HTTPS API (https://cloudflare-dns.com). It resolves WhoIs throught RDAP API (https://rdap.org).",
|
||||||
|
});
|
||||||
Reference in new issue
Block a user