💥 破坏性更新 咱不推荐更新

This commit is contained in:
7836246
2024-03-25 06:55:06 +08:00
parent 9bb0fbd9a6
commit 410dc1ac58
52 changed files with 3645 additions and 1337 deletions
+38 -21
View File
@@ -1,11 +1,10 @@
import dns from 'node:dns/promises';
// 定义 DNS 服务器配置
const dnsServers:any = {
const dnsServers: any = {
google: 'https://dns.google/resolve',
cloudflare: 'http://1.1.1.1/dns-query',
aliyun: 'https://223.5.5.5/resolve',
tencent: 'https://doh.pub/dns-query',
nuxt: '/api/resolve',
};
interface Resp {
@@ -23,57 +22,75 @@ interface soaRecord {
expire: number;
minttl: number;
}
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const domain = body.domain;
const flag = body.flag;
const dnsServerKey = body.dnsServer;
//判断是否开启DNS
if (!flag) {
return {
status: 200,
body: 'DNS is not open'
}
}
switch (dnsServerKey) {
case 'google':
return await $fetch(dnsServers.google, {
return await $fetch(dnsServers.google, {
params: {
name: domain,
type: 'A',
}
});
case 'tencent':
return await $fetch(dnsServers.tencent, {
return await $fetch(dnsServers.tencent, {
params: {
name: domain,
type: 'A',
}
});
case 'cloudflare':
const resp = await $fetch(dnsServers.cloudflare, {
const resp = await $fetch(dnsServers.cloudflare, {
method: 'GET',
params: {
name: domain,
},
},
headers: {
"Accept": "application/dns-json", // 设置期望的响应数据类型
}
}).then((resp:any) => {
}).then((resp: any) => {
return resp.text()
})
})
return JSON.parse(resp);
case 'aliyun':
return await $fetch(dnsServers.aliyun, {
return await $fetch(dnsServers.aliyun, {
params: {
name: domain,
type: '1',
}
});
case 'nuxt':
return await $fetch(dnsServers.nuxt, {
method: 'POST',
body: {
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;
// 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;
return null
}
});
+55
View File
@@ -0,0 +1,55 @@
// 定义 DNS 服务器配置
const doMainServers: any = {
whocx: 'https://who.cx/api/price',
};
interface DomainInfoResponse {
code: number;
currency: string;
currency_symbol: string;
domain: string;
new: string;
renew: string;
premium: boolean;
}
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const domain = body.domain;
const flag = body.flag;
const domainServerKey = body.domainServer;
//判断是否开启DNS
console.log(flag)
if (!flag) {
return {
status: 200,
data: {
status: 'success',
}
}
}
switch (domainServerKey) {
case 'whocx':
const res: any = await $fetch(doMainServers.whocx, {
method: "GET",
params: {
domain: domain,
}
});
return {
code: 200,
currency: res.currency,
currency_symbol: res.currency_symbol,
domain: res.domain,
new: res.new,
renew: res.renew,
premium: false,
} as DomainInfoResponse
default:
return null
}
});
+61
View File
@@ -0,0 +1,61 @@
// server/api/dns-query.ts
import {resolve4} from 'dns/promises';
interface DNSQueryResponse {
Status: number;
TC: boolean;
RD: boolean;
RA: boolean;
AD: boolean;
CD: boolean;
Question: {
name: string;
type: number;
};
Answer?: Array<{
name: string;
TTL: number;
type: number;
data: string;
}>;
message?: string;
}
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const queryName: string = body.name // 如果请求体中没有提供域名,默认查询 'baidu.com'
try {
const addresses: string[] = await resolve4(queryName);
const answers = addresses.map((address) => ({
name: `${queryName}.`,
TTL: 269, // 示例中的 TTL 值是硬编码的
type: 1, // 表示 A 记录
data: address,
}));
const response: DNSQueryResponse = {
Status: 0,
TC: false,
RD: true,
RA: true,
AD: false,
CD: false,
Question: {
name: `${queryName}.`,
type: 1,
},
Answer: answers,
};
return response;
} catch (error) {
console.error(error);
const response: DNSQueryResponse = {
AD: false, CD: false, Question: {name: "", type: 0}, RA: false, RD: false, TC: false,
Status: 2, // 使用 2 表示错误状态
message: 'DNS query failed'
};
return response;
}
});
+2 -39
View File
@@ -5,44 +5,7 @@ export default defineEventHandler(async (event) => {
try {
const res = await whois(body.domain)
return res._raw
}catch (e) {
return `No match for "${body.domain}".
` +
`>>> Last update of whois database: ${new Date()} <<<
` +
'\n' +
'NOTICE: The expiration date displayed in this record is the date the\n' +
'registrar\'s sponsorship of the domain name registration in the registry is\n' +
'currently set to expire. This date does not necessarily reflect the expiration\n' +
'date of the domain name registrant\'s agreement with the sponsoring\n' +
'registrar. Users may consult the sponsoring registrar\'s Whois database to\n' +
'view the registrar\'s reported date of expiration for this registration.\n' +
'\n' +
'TERMS OF USE: You are not authorized to access or query our Whois\n' +
'database through the use of electronic processes that are high-volume and\n' +
'automated except as reasonably necessary to register domain names or\n' +
'modify existing registrations; the Data in VeriSign Global Registry\n' +
'Services\' ("VeriSign") Whois database is provided by VeriSign for\n' +
'information purposes only, and to assist persons in obtaining information\n' +
'about or related to a domain name registration record. VeriSign does not\n' +
'guarantee its accuracy. By submitting a Whois query, you agree to abide\n' +
'by the following terms of use: You agree that you may use this Data only\n' +
'for lawful purposes and that under no circumstances will you use this Data\n' +
'to: (1) allow, enable, or otherwise support the transmission of mass\n' +
'unsolicited, commercial advertising or solicitations via e-mail, telephone,\n' +
'or facsimile; or (2) enable high volume, automated, electronic processes\n' +
'that apply to VeriSign (or its computer systems). The compilation,\n' +
'repackaging, dissemination or other use of this Data is expressly\n' +
'prohibited without the prior written consent of VeriSign. You agree not to\n' +
'use electronic processes that are automated and high-volume to access or\n' +
'query the Whois database except as reasonably necessary to register\n' +
'domain names or modify existing registrations. VeriSign reserves the right\n' +
'to restrict your access to the Whois database in its sole discretion to ensure\n' +
'operational stability. VeriSign may restrict or terminate your access to the\n' +
'Whois database for failure to abide by these terms of use. VeriSign\n' +
'reserves the right to modify these terms at any time.\n' +
'\n' +
'The Registry database contains ONLY .COM, .NET, .EDU domains and\n' +
'Registrars.'
} catch (e) {
return e
}
})