diff --git a/components/dns/ApiChanges.vue b/components/dns/ApiChanges.vue new file mode 100644 index 0000000..040ba6b --- /dev/null +++ b/components/dns/ApiChanges.vue @@ -0,0 +1,65 @@ + + + diff --git a/components/dns/CloudflareList.vue b/components/dns/CloudflareList.vue new file mode 100644 index 0000000..1c32405 --- /dev/null +++ b/components/dns/CloudflareList.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/components/dns/DefaultList.vue b/components/dns/DefaultList.vue new file mode 100644 index 0000000..16a07be --- /dev/null +++ b/components/dns/DefaultList.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/components/dns/InfoList.vue b/components/dns/InfoList.vue new file mode 100644 index 0000000..c1adcf6 --- /dev/null +++ b/components/dns/InfoList.vue @@ -0,0 +1,43 @@ + + + + + diff --git a/package.json b/package.json index fc76fde..9072409 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "@nuxtjs/tailwindcss": "^6.11.4", "@pinia/nuxt": "^0.5.1", "nuxt": "^3.10.3", - "socks": "^2.8.1", "vue": "^3.4.21", "vue-router": "^4.3.0" }, diff --git a/pages/dns/[domain].html.vue b/pages/dns/[domain].html.vue index b52250a..ce123a4 100644 --- a/pages/dns/[domain].html.vue +++ b/pages/dns/[domain].html.vue @@ -2,6 +2,7 @@ import {useStyleStore} from "~/stores/style"; import {AdjustTimeToUTCOffset} from "~/utils/utc"; import {useTimeStore} from "~/stores/time"; +import DnsInfo from "~/components/dns/InfoList.vue"; const {t} = useI18n() @@ -9,21 +10,24 @@ const route = useRoute(); const {domain} = route.params; const domainData = domain.replace(/_/g, '.') + +const timeStore = useTimeStore() +const styleStore = useStyleStore() +const localePath = useLocalePath() + +styleStore.setIsPage(true) + const {data, pending, error, refresh} = await useAsyncData( 'dns', () => $fetch('/api/dns', { method: 'POST', - body: JSON.stringify({domain: 'xukangr.com'}) + body: { + domain: domainData, + dnsServer:timeStore.getDnsServer + } }) ) -const timeStore = useTimeStore() -const styleStore = useStyleStore() - -styleStore.setIsPage(true) - -const localePath = useLocalePath() - if (!error.value) { styleStore.addOrUpdateHistory( { @@ -54,50 +58,30 @@ useHead({
-

{{ t('dns.dnsResult') }}

-
-
-

{{ t('dns.aRecord') }}

-
-
    -
  • - IP: - {{ record.Record }} - TTL: {{ record.TTL }} -
  • -
-
-
-
-

{{ t('dns.nsRecord') }}

-
-
    -
  • - {{ record.Record }} - TTL: {{ record.TTL }} -
  • -
-
-
-
-

{{ t('dns.soaRecord') }}

-
-
    -
  • MName: {{ data.SOA.MName }}
  • -
  • Email: {{ data.SOA.Email }}
  • -
  • Serial: {{ data.SOA.Serial }}
  • -
  • Refresh: {{ data.SOA.Refresh }}
  • -
  • Retry: {{ data.SOA.Retry }}
  • -
  • Expire: {{ data.SOA.Expire }}
  • -
  • Minimum TTL: {{ data.SOA.MinimumTTL }}
  • -
-
-
+
+

{{ t('dns.dnsResult') }} + {{ timeStore.getDnsServer }} +

+ + +
+ + + + + + + + +
diff --git a/pages/whois/[domain].html.vue b/pages/whois/[domain].html.vue index 62c0ed4..72458fd 100644 --- a/pages/whois/[domain].html.vue +++ b/pages/whois/[domain].html.vue @@ -18,7 +18,7 @@ const styleStore = useStyleStore() const localePath = useLocalePath() const {data, pending, error, refresh} = await useAsyncData( - 'mountains', + 'whois', () => $fetch('/api/whois', { method: 'POST', body: JSON.stringify({domain: domainData}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0213601..82ef38d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,9 +17,6 @@ dependencies: nuxt: specifier: ^3.10.3 version: 3.10.3(rollup@4.12.0)(typescript@5.3.3)(vite@5.1.4) - socks: - specifier: ^2.8.1 - version: 2.8.1 vue: specifier: ^3.4.21 version: 3.4.21(typescript@5.3.3) diff --git a/server/api/dns.post.ts b/server/api/dns.post.ts index e0b73dc..4a28cba 100644 --- a/server/api/dns.post.ts +++ b/server/api/dns.post.ts @@ -1,31 +1,79 @@ import dns from 'node:dns/promises'; + +// 定义 DNS 服务器配置 +const dnsServers:any = { + google: 'https://dns.google/resolve', + cloudflare: 'http://cloudflare-dns.com/dns-query', + aliyun: 'https://223.5.5.5/resolve', + tencent: 'https://doh.pub/dns-query', +}; + +interface Resp { + aRecords: string[]; + nsRecords: string[]; + soaRecord: soaRecord; +} + +interface soaRecord { + nsname: string; + hostmaster: string; + serial: number; + refresh: number; + retry: number; + expire: number; + minttl: number; +} export default defineEventHandler(async (event) => { - const body = await readBody(event) - + const body = await readBody(event); const domain = body.domain; - if (!domain) { - return { error: 'Missing domain' }; - } - try { - const aRecords = await dns.resolve(domain, 'A'); - const nsRecords = await dns.resolve(domain, 'NS'); - const soaRecord = await dns.resolveSoa(domain); - return { - A: aRecords.map(ip => ({ TTL: '600', Record: ip })), // 示例中的TTL是假设的 - NS: nsRecords.map(ns => ({ TTL: '21600', Record: ns })), // 示例中的TTL是假设的 - SOA: { - MName: soaRecord.nsname, - Email: soaRecord.hostmaster, - Serial: soaRecord.serial, - Refresh: soaRecord.refresh, - Retry: soaRecord.retry, - Expire: soaRecord.expire, - MinimumTTL: soaRecord.minttl, - } - }; - } catch (error) { - console.error(`Error fetching DNS records for ${domain}:`, error); - return { error: 'Failed to fetch DNS records' }; + const dnsServerKey = body.dnsServer; + + switch (dnsServerKey) { + case 'google': + return await $fetch(dnsServers.google, { + params: { + name: domain, + type: 'A', + } + }); + case 'tencent': + return await $fetch(dnsServers.tencent, { + params: { + name: domain, + type: 'A', + } + }); + case 'cloudflare': + const resp = await $fetch('http://1.1.1.1/dns-query', { + method: 'GET', + params: { + name: domain, + }, + headers: { + "Accept": "application/dns-json", // 设置期望的响应数据类型 + } + }).then((resp:any) => { + return resp.text() + }) + return JSON.parse(resp); + case 'aliyun': + return await $fetch(dnsServers.aliyun, { + params: { + name: domain, + type: '1', + } + }); + default: + const resolver = new dns.Resolver(); + + const aRecords = await resolver.resolve(domain, 'A'); + const nsRecords = await resolver.resolve(domain, 'NS'); + const soaRecord = await resolver.resolveSoa(domain); + return { + aRecords: aRecords, + nsRecords: nsRecords, + soaRecord: soaRecord, + } as Resp; } -}) +}); diff --git a/stores/time.ts b/stores/time.ts index 41838f0..4f7e355 100644 --- a/stores/time.ts +++ b/stores/time.ts @@ -4,8 +4,25 @@ export const useTimeStore = defineStore('timeZones', { state: () => { return { timeZones: 'UTC+8', + dnsServer: '', } }, + actions: { + setTimeZones(timeZones: string) { + this.timeZones = timeZones + }, + setDnsServer(dnsServer: string) { + this.dnsServer = dnsServer + }, + }, + getters: { + getTimeZones(state) { + return state.timeZones + }, + getDnsServer(state) { + return state.dnsServer + }, + }, persist: { storage: persistedState.cookiesWithOptions({ sameSite: 'strict',