-
Notifications
You must be signed in to change notification settings - Fork 438
Expand file tree
/
Copy path_worker.js
More file actions
1684 lines (1482 loc) · 61.6 KB
/
_worker.js
File metadata and controls
1684 lines (1482 loc) · 61.6 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
let DoH = "cloudflare-dns.com";
const jsonDoH = `https://${DoH}/resolve`;
const dnsDoH = `https://${DoH}/dns-query`;
let DoH路径 = 'dns-query';
export default {
async fetch(request, env) {
if (env.DOH) {
DoH = env.DOH;
const match = DoH.match(/:\/\/([^\/]+)/);
if (match) {
DoH = match[1];
}
}
DoH路径 = env.PATH || env.TOKEN || DoH路径;//DoH路径也单独设置 变量PATH
if (DoH路径.includes("/")) DoH路径 = DoH路径.split("/")[1];
const url = new URL(request.url);
const path = url.pathname;
const hostname = url.hostname;
// 处理 OPTIONS 预检请求
if (request.method === 'OPTIONS') {
return new Response(null, {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': '*',
'Access-Control-Max-Age': '86400'
}
});
}
// 如果请求路径,则作为 DoH 服务器处理
if (path === `/${DoH路径}`) {
return await DOHRequest(request);
}
// 添加IP地理位置信息查询代理
if (path === '/ip-info') {
if (env.TOKEN) {
const token = url.searchParams.get('token');
if (token != env.TOKEN) {
return new Response(JSON.stringify({
status: "error",
message: "Token不正确",
code: "AUTH_FAILED",
timestamp: new Date().toISOString()
}, null, 4), {
status: 403,
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
}
}
const ip = url.searchParams.get('ip') || request.headers.get('CF-Connecting-IP');
if (!ip) {
return new Response(JSON.stringify({
status: "error",
message: "IP参数未提供",
code: "MISSING_PARAMETER",
timestamp: new Date().toISOString()
}, null, 4), {
status: 400,
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
}
try {
// 使用Worker代理请求HTTP的IP API
const response = await fetch(`http://ip-api.com/json/${ip}?lang=zh-CN`);
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
const data = await response.json();
// 添加时间戳到成功的响应数据中
data.timestamp = new Date().toISOString();
// 返回数据给客户端,并添加CORS头
return new Response(JSON.stringify(data, null, 4), {
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
} catch (error) {
console.error("IP查询失败:", error);
return new Response(JSON.stringify({
status: "error",
message: `IP查询失败: ${error.message}`,
code: "API_REQUEST_FAILED",
query: ip,
timestamp: new Date().toISOString(),
details: {
errorType: error.name,
stack: error.stack ? error.stack.split('\n')[0] : null
}
}, null, 4), {
status: 500,
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
}
}
// 如果请求参数中包含 domain 和 doh,则执行 DNS 解析
if (url.searchParams.has("doh")) {
const domain = url.searchParams.get("domain") || url.searchParams.get("name") || "www.google.com";
const doh = url.searchParams.get("doh") || dnsDoH;
const type = url.searchParams.get("type") || "all"; // 默认同时查询 A 和 AAAA
// 如果使用的是当前站点,则使用 DoH 服务
if (doh.includes(url.host)) {
return await handleLocalDohRequest(domain, type, hostname);
}
try {
// 根据请求类型进行不同的处理
if (type === "all") {
// 同时请求 A、AAAA 和 NS 记录,使用新的查询函数
const ipv4Result = await queryDns(doh, domain, "A");
const ipv6Result = await queryDns(doh, domain, "AAAA");
const nsResult = await queryDns(doh, domain, "NS");
// 合并结果 - 修改Question字段处理方式以兼容不同格式
const combinedResult = {
Status: ipv4Result.Status || ipv6Result.Status || nsResult.Status,
TC: ipv4Result.TC || ipv6Result.TC || nsResult.TC,
RD: ipv4Result.RD || ipv6Result.RD || nsResult.RD,
RA: ipv4Result.RA || ipv6Result.RA || nsResult.RA,
AD: ipv4Result.AD || ipv6Result.AD || nsResult.AD,
CD: ipv4Result.CD || ipv6Result.CD || nsResult.CD,
// 修改处理Question字段的方式,兼容对象格式和数组格式
Question: [],
Answer: [...(ipv4Result.Answer || []), ...(ipv6Result.Answer || [])],
ipv4: {
records: ipv4Result.Answer || []
},
ipv6: {
records: ipv6Result.Answer || []
},
ns: {
records: []
}
};
// 正确处理Question字段,无论是对象还是数组
if (ipv4Result.Question) {
if (Array.isArray(ipv4Result.Question)) {
combinedResult.Question.push(...ipv4Result.Question);
} else {
combinedResult.Question.push(ipv4Result.Question);
}
}
if (ipv6Result.Question) {
if (Array.isArray(ipv6Result.Question)) {
combinedResult.Question.push(...ipv6Result.Question);
} else {
combinedResult.Question.push(ipv6Result.Question);
}
}
if (nsResult.Question) {
if (Array.isArray(nsResult.Question)) {
combinedResult.Question.push(...nsResult.Question);
} else {
combinedResult.Question.push(nsResult.Question);
}
}
// 处理NS记录 - 可能在Answer或Authority部分
const nsRecords = [];
// 从Answer部分收集NS记录
if (nsResult.Answer && nsResult.Answer.length > 0) {
nsResult.Answer.forEach(record => {
if (record.type === 2) { // NS记录类型是2
nsRecords.push(record);
}
});
}
// 从Authority部分收集NS和SOA记录
if (nsResult.Authority && nsResult.Authority.length > 0) {
nsResult.Authority.forEach(record => {
if (record.type === 2 || record.type === 6) { // NS=2, SOA=6
nsRecords.push(record);
// 也添加到总Answer数组
combinedResult.Answer.push(record);
}
});
}
// 设置NS记录集合
combinedResult.ns.records = nsRecords;
return new Response(JSON.stringify(combinedResult, null, 2), {
headers: { "content-type": "application/json; charset=UTF-8" }
});
} else {
// 普通的单类型查询,使用新的查询函数
const result = await queryDns(doh, domain, type);
return new Response(JSON.stringify(result, null, 2), {
headers: { "content-type": "application/json; charset=UTF-8" }
});
}
} catch (err) {
console.error("DNS 查询失败:", err);
return new Response(JSON.stringify({
error: `DNS 查询失败: ${err.message}`,
doh: doh,
domain: domain,
stack: err.stack
}, null, 2), {
headers: { "content-type": "application/json; charset=UTF-8" },
status: 500
});
}
}
if (env.URL302) return Response.redirect(env.URL302, 302);
else if (env.URL) {
if (env.URL.toString().toLowerCase() == 'nginx') {
return new Response(await nginx(), {
headers: {
'Content-Type': 'text/html; charset=UTF-8',
},
});
} else return await 代理URL(env.URL, url);
} else return await HTML();
}
}
// 查询DNS的通用函数
async function queryDns(dohServer, domain, type) {
// 构造 DoH 请求 URL
const dohUrl = new URL(dohServer);
dohUrl.searchParams.set("name", domain);
dohUrl.searchParams.set("type", type);
// 尝试多种请求头格式
const fetchOptions = [
// 标准 application/dns-json
{
headers: { 'Accept': 'application/dns-json' }
},
// 部分服务使用没有指定 Accept 头的请求
{
headers: {}
},
// 另一个尝试 application/json
{
headers: { 'Accept': 'application/json' }
},
// 稳妥起见,有些服务可能需要明确的用户代理
{
headers: {
'Accept': 'application/dns-json',
'User-Agent': 'Mozilla/5.0 DNS Client'
}
}
];
let lastError = null;
// 依次尝试不同的请求头组合
for (const options of fetchOptions) {
try {
const response = await fetch(dohUrl.toString(), options);
// 如果请求成功,解析JSON
if (response.ok) {
const contentType = response.headers.get('content-type') || '';
// 检查内容类型是否兼容
if (contentType.includes('json') || contentType.includes('dns-json')) {
return await response.json();
} else {
// 对于非标准的响应,仍尝试进行解析
const textResponse = await response.text();
try {
return JSON.parse(textResponse);
} catch (jsonError) {
throw new Error(`无法解析响应为JSON: ${jsonError.message}, 响应内容: ${textResponse.substring(0, 100)}`);
}
}
}
// 错误情况记录,继续尝试下一个选项
const errorText = await response.text();
lastError = new Error(`DoH 服务器返回错误 (${response.status}): ${errorText.substring(0, 200)}`);
} catch (err) {
// 记录错误,继续尝试下一个选项
lastError = err;
}
}
// 所有尝试都失败,抛出最后一个错误
throw lastError || new Error("无法完成 DNS 查询");
}
// 处理本地 DoH 请求的函数 - 直接调用 DoH,而不是自身服务
async function handleLocalDohRequest(domain, type, hostname) {
try {
if (type === "all") {
// 同时请求 A、AAAA 和 NS 记录
const ipv4Promise = queryDns(dnsDoH, domain, "A");
const ipv6Promise = queryDns(dnsDoH, domain, "AAAA");
const nsPromise = queryDns(dnsDoH, domain, "NS");
// 等待所有请求完成
const [ipv4Result, ipv6Result, nsResult] = await Promise.all([ipv4Promise, ipv6Promise, nsPromise]);
// 准备NS记录数组
const nsRecords = [];
// 从Answer和Authority部分收集NS记录
if (nsResult.Answer && nsResult.Answer.length > 0) {
nsRecords.push(...nsResult.Answer.filter(record => record.type === 2));
}
if (nsResult.Authority && nsResult.Authority.length > 0) {
nsRecords.push(...nsResult.Authority.filter(record => record.type === 2 || record.type === 6));
}
// 合并结果
const combinedResult = {
Status: ipv4Result.Status || ipv6Result.Status || nsResult.Status,
TC: ipv4Result.TC || ipv6Result.TC || nsResult.TC,
RD: ipv4Result.RD || ipv6Result.RD || nsResult.RD,
RA: ipv4Result.RA || ipv6Result.RA || nsResult.RA,
AD: ipv4Result.AD || ipv6Result.AD || nsResult.AD,
CD: ipv4Result.CD || ipv6Result.CD || nsResult.CD,
Question: [...(ipv4Result.Question || []), ...(ipv6Result.Question || []), ...(nsResult.Question || [])],
Answer: [
...(ipv4Result.Answer || []),
...(ipv6Result.Answer || []),
...nsRecords
],
ipv4: {
records: ipv4Result.Answer || []
},
ipv6: {
records: ipv6Result.Answer || []
},
ns: {
records: nsRecords
}
};
return new Response(JSON.stringify(combinedResult, null, 2), {
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
} else {
// 普通的单类型查询
const result = await queryDns(dnsDoH, domain, type);
return new Response(JSON.stringify(result, null, 2), {
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
}
} catch (err) {
console.error("DoH 查询失败:", err);
return new Response(JSON.stringify({
error: `DoH 查询失败: ${err.message}`,
stack: err.stack
}, null, 2), {
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
},
status: 500
});
}
}
// DoH 请求处理函数
async function DOHRequest(request) {
const { method, headers, body } = request;
const UA = headers.get('User-Agent') || 'DoH Client';
const url = new URL(request.url);
const { searchParams } = url;
try {
// 直接访问端点的处理
if (method === 'GET' && !url.search) {
// 如果是直接访问或浏览器访问,返回友好信息
return new Response('Bad Request', {
status: 400,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Access-Control-Allow-Origin': '*'
}
});
}
// 根据请求方法和参数构建转发请求
let response;
if (method === 'GET' && searchParams.has('name')) {
const searchDoH = searchParams.has('type') ? url.search : url.search + '&type=A';
// 处理 JSON 格式的 DoH 请求
response = await fetch(dnsDoH + searchDoH, {
headers: {
'Accept': 'application/dns-json',
'User-Agent': UA
}
});
// 如果 DoHUrl 请求非成功(状态码 200),则再请求 jsonDoH
if (!response.ok) response = await fetch(jsonDoH + searchDoH, {
headers: {
'Accept': 'application/dns-json',
'User-Agent': UA
}
});
} else if (method === 'GET') {
// 处理 base64url 格式的 GET 请求
response = await fetch(dnsDoH + url.search, {
headers: {
'Accept': 'application/dns-message',
'User-Agent': UA
}
});
} else if (method === 'POST') {
// 处理 POST 请求
response = await fetch(dnsDoH, {
method: 'POST',
headers: {
'Accept': 'application/dns-message',
'Content-Type': 'application/dns-message',
'User-Agent': UA
},
body: body
});
} else {
// 其他不支持的请求方式
return new Response('不支持的请求格式: DoH请求需要包含name或dns参数,或使用POST方法', {
status: 400,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Access-Control-Allow-Origin': '*'
}
});
}
if (!response.ok) {
const errorText = await response.text();
throw new Error(`DoH 返回错误 (${response.status}): ${errorText.substring(0, 200)}`);
}
// 创建一个新的响应头对象
const responseHeaders = new Headers(response.headers);
// 设置跨域资源共享 (CORS) 的头部信息
responseHeaders.set('Access-Control-Allow-Origin', '*');
responseHeaders.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
responseHeaders.set('Access-Control-Allow-Headers', '*');
// 检查是否为JSON格式的DoH请求,确保设置正确的Content-Type
if (method === 'GET' && searchParams.has('name')) {
// 对于JSON格式的DoH请求,明确设置Content-Type为application/json
responseHeaders.set('Content-Type', 'application/json');
}
// 返回响应
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: responseHeaders
});
} catch (error) {
console.error("DoH 请求处理错误:", error);
return new Response(JSON.stringify({
error: `DoH 请求处理错误: ${error.message}`,
stack: error.stack
}, null, 4), {
status: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
});
}
}
async function HTML() {
// 否则返回 HTML 页面
const html = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DNS-over-HTTPS Resolver</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<link rel="icon"
href="https://cf-assets.www.cloudflare.com/dzlvafdwdttg/6TaQ8Q7BDmdAFRoHpDCb82/8d9bc52a2ac5af100de3a9adcf99ffaa/security-shield-protection-2.svg"
type="image/x-icon">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
min-height: 100vh;
padding: 0;
margin: 0;
line-height: 1.6;
background: url('https://cf-assets.www.cloudflare.com/dzlvafdwdttg/5B5shLB8bSKIyB9NJ6R1jz/87e7617be2c61603d46003cb3f1bd382/Hero-globe-bg-takeover-xxl.png'),
linear-gradient(135deg, rgba(253, 101, 60, 0.85) 0%, rgba(251,152,30, 0.85) 100%);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
padding: 30px 20px;
box-sizing: border-box;
}
.page-wrapper {
width: 100%;
max-width: 800px;
margin: 0 auto;
}
.container {
width: 100%;
max-width: 800px;
margin: 20px auto;
background-color: rgba(255, 255, 255, 0.65);
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
padding: 30px;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.4);
}
h1 {
/* 创建文字渐变效果 */
background-image: linear-gradient(to right, rgb(249, 171, 76), rgb(252, 103, 60));
/* 回退颜色,用于不支持渐变文本的浏览器 */
color: rgb(252, 103, 60);
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
-moz-text-fill-color: transparent;
font-weight: 600;
/* 注意:渐变文本和阴影效果同时使用可能不兼容,暂时移除阴影 */
text-shadow: none;
}
.card {
margin-bottom: 20px;
border: none;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
background-color: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
}
.card-header {
background-color: rgba(255, 242, 235, 0.9);
font-weight: 600;
padding: 12px 20px;
border-bottom: none;
}
.form-label {
font-weight: 500;
margin-bottom: 8px;
color: rgb(70, 50, 40);
}
.form-select,
.form-control {
border-radius: 6px;
padding: 10px;
border: 1px solid rgba(253, 101, 60, 0.3);
background-color: rgba(255, 255, 255, 0.9);
}
.btn-primary {
background-color: rgb(253, 101, 60);
border: none;
border-radius: 6px;
padding: 10px 20px;
font-weight: 500;
transition: all 0.2s ease;
}
.btn-primary:hover {
background-color: rgb(230, 90, 50);
transform: translateY(-1px);
}
pre {
background-color: rgba(255, 245, 240, 0.9);
padding: 15px;
border-radius: 6px;
border: 1px solid rgba(253, 101, 60, 0.2);
white-space: pre-wrap;
word-break: break-all;
font-family: Consolas, Monaco, 'Andale Mono', monospace;
font-size: 14px;
max-height: 400px;
overflow: auto;
}
.loading {
display: none;
text-align: center;
padding: 20px 0;
}
.loading-spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left: 4px solid rgb(253, 101, 60);
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
margin: 0 auto 10px;
}
.badge {
margin-left: 5px;
font-size: 11px;
vertical-align: middle;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.footer {
margin-top: 30px;
text-align: center;
color: rgba(255, 255, 255, 0.9);
font-size: 14px;
}
.beian-info {
text-align: center;
font-size: 13px;
}
.beian-info a {
color: var(--primary-color);
text-decoration: none;
border-bottom: 1px dashed var(--primary-color);
padding-bottom: 2px;
}
.beian-info a:hover {
border-bottom-style: solid;
}
@media (max-width: 576px) {
.container {
padding: 20px;
}
.github-corner:hover .octo-arm {
animation: none;
}
.github-corner .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
}
.error-message {
color: #e63e00;
margin-top: 10px;
}
.success-message {
color: #e67e22;
}
.nav-tabs .nav-link {
border-top-left-radius: 6px;
border-top-right-radius: 6px;
padding: 8px 16px;
font-weight: 500;
color: rgb(150, 80, 50);
}
.nav-tabs .nav-link.active {
background-color: rgba(255, 245, 240, 0.8);
border-bottom-color: rgba(255, 245, 240, 0.8);
color: rgb(253, 101, 60);
}
.tab-content {
background-color: rgba(255, 245, 240, 0.8);
border-radius: 0 0 6px 6px;
padding: 15px;
border: 1px solid rgba(253, 101, 60, 0.2);
border-top: none;
}
.ip-record {
padding: 5px 10px;
margin-bottom: 5px;
border-radius: 4px;
background-color: rgba(255, 255, 255, 0.9);
border: 1px solid rgba(253, 101, 60, 0.15);
}
.ip-record:hover {
background-color: rgba(255, 235, 225, 0.9);
}
.ip-address {
font-family: monospace;
font-weight: 600;
min-width: 130px;
color: rgb(80, 60, 50);
cursor: pointer;
position: relative;
transition: color 0.2s ease;
display: inline-block;
}
.ip-address:hover {
color: rgb(253, 101, 60);
}
.ip-address:after {
content: '';
position: absolute;
left: 100%; /* 从IP地址的右侧开始定位 */
top: 0;
opacity: 0;
white-space: nowrap;
font-size: 12px;
color: rgb(253, 101, 60);
transition: opacity 0.3s ease;
font-family: 'Segoe UI', sans-serif;
font-weight: normal;
}
.ip-address.copied:after {
content: '✓ 已复制';
opacity: 1;
}
.result-summary {
margin-bottom: 15px;
padding: 10px;
background-color: rgba(255, 235, 225, 0.8);
border-radius: 6px;
}
.result-tabs {
margin-bottom: 20px;
}
.geo-info {
margin: 0 10px;
font-size: 0.85em;
flex-grow: 1;
text-align: center;
}
.geo-country {
color: rgb(230, 90, 50);
font-weight: 500;
padding: 2px 6px;
background-color: rgba(255, 245, 240, 0.8);
border-radius: 4px;
display: inline-block;
}
.geo-as {
color: rgb(253, 101, 60);
padding: 2px 6px;
background-color: rgba(255, 245, 240, 0.8);
border-radius: 4px;
margin-left: 5px;
display: inline-block;
}
.geo-blocked {
color: #ffffff;
background-color: #dc3545;
padding: 2px 8px;
border-radius: 4px;
font-weight: 600;
display: inline-block;
animation: pulse-red 2s infinite;
}
@keyframes pulse-red {
0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
70% { box-shadow: 0 0 0 10px rgba(220, 53, 69, 0); }
100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}
.geo-loading {
color: rgb(150, 100, 80);
font-style: italic;
}
.ttl-info {
min-width: 80px;
text-align: right;
color: rgb(180, 90, 60);
}
.copy-link {
color: rgb(253, 101, 60);
text-decoration: none;
border-bottom: 1px dashed rgb(253, 101, 60);
padding-bottom: 2px;
cursor: pointer;
position: relative;
}
.copy-link:hover {
border-bottom-style: solid;
}
.copy-link:after {
content: '';
position: absolute;
top: 0;
right: -65px;
opacity: 0;
white-space: nowrap;
color: rgb(253, 101, 60);
font-size: 12px;
transition: opacity 0.3s ease;
}
.copy-link.copied:after {
content: '✓ 已复制';
opacity: 1;
}
.github-corner svg {
fill: rgb(255, 255, 255);
color: rgb(251,152,30);
position: absolute;
top: 0;
right: 0;
border: 0;
width: 80px;
height: 80px;
}
.github-corner:hover .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
/* 添加章鱼猫挥手动画关键帧 */
@keyframes octocat-wave {
0%, 100% { transform: rotate(0); }
20%, 60% { transform: rotate(-25deg); }
40%, 80% { transform: rotate(10deg); }
}
@media (max-width: 576px) {
.container {
padding: 20px;
}
.github-corner:hover .octo-arm {
animation: none;
}
.github-corner .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
}
</style>
</head>
<body>
<a href="https://github.com/cmliu/CF-Workers-DoH" target="_blank" class="github-corner" aria-label="View source on Github">
<svg viewBox="0 0 250 250" aria-hidden="true">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
<path
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
fill="currentColor" class="octo-body"></path>
</svg>
</a>
<div class="container">
<h1 class="text-center mb-4">DNS-over-HTTPS Resolver</h1>
<div class="card">
<div class="card-header">DNS 查询设置</div>
<div class="card-body">
<form id="resolveForm">
<div class="mb-3">
<label for="dohSelect" class="form-label">选择 DoH 地址:</label>
<select id="dohSelect" class="form-select">
<option value="current" selected id="currentDohOption">自动 (当前站点)</option>
<option value="https://dns.alidns.com/resolve">https://dns.alidns.com/resolve (阿里)</option>
<option value="https://sm2.doh.pub/dns-query">https://sm2.doh.pub/dns-query (腾讯)</option>
<option value="https://doh.360.cn/resolve">https://doh.360.cn/resolve (360)</option>
<option value="https://cloudflare-dns.com/dns-query">https://cloudflare-dns.com/dns-query (Cloudflare)</option>
<option value="https://dns.google/resolve">https://dns.google/resolve (谷歌)</option>
<option value="https://dns.adguard-dns.com/resolve">https://dns.adguard-dns.com/resolve (AdGuard)</option>
<option value="https://dns.sb/dns-query">https://dns.sb/dns-query (DNS.SB)</option>
<option value="https://zero.dns0.eu/">https://zero.dns0.eu (dns0.eu)</option>
<option value="https://dns.nextdns.io"> https://dns.nextdns.io (NextDNS)</option>
<option value="https://dns.rabbitdns.org/dns-query">https://dns.rabbitdns.org/dns-query (Rabbit DNS)</option>
<option value="https://basic.rethinkdns.com/">https://basic.rethinkdns.com (RethinkDNS)</option>
<option value="https://v.recipes/dns-query">https://v.recipes/dns-query (v.recipes DNS)</option>
<option value="custom">自定义...</option>
</select>
</div>
<div id="customDohContainer" class="mb-3" style="display:none;">
<label for="customDoh" class="form-label">输入自定义 DoH 地址:</label>
<input type="text" id="customDoh" class="form-control" placeholder="https://example.com/dns-query">
</div>
<div class="mb-3">
<label for="domain" class="form-label">待解析域名:</label>
<div class="input-group">
<input type="text" id="domain" class="form-control" value="www.google.com"
placeholder="输入域名,如 example.com">
<button type="button" class="btn btn-outline-secondary" id="clearBtn">清除</button>
</div>
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary flex-grow-1">解析</button>
<button type="button" class="btn btn-outline-primary" id="getJsonBtn">Get Json</button>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<span>解析结果</span>
<button class="btn btn-sm btn-outline-secondary" id="copyBtn" style="display: none;">复制结果</button>
</div>
<div class="card-body">
<div id="loading" class="loading">
<div class="loading-spinner"></div>
<p>正在查询中,请稍候...</p>
</div>
<!-- 结果展示区,包含选项卡 -->
<div id="resultContainer" style="display: none;">
<ul class="nav nav-tabs result-tabs" id="resultTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="ipv4-tab" data-bs-toggle="tab" data-bs-target="#ipv4" type="button"
role="tab">IPv4 地址</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="ipv6-tab" data-bs-toggle="tab" data-bs-target="#ipv6" type="button"
role="tab">IPv6 地址</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="ns-tab" data-bs-toggle="tab" data-bs-target="#ns" type="button" role="tab">NS
记录</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="raw-tab" data-bs-toggle="tab" data-bs-target="#raw" type="button"
role="tab">原始数据</button>
</li>
</ul>
<div class="tab-content" id="resultTabContent">
<div class="tab-pane fade show active" id="ipv4" role="tabpanel" aria-labelledby="ipv4-tab">
<div class="result-summary" id="ipv4Summary"></div>
<div id="ipv4Records"></div>
</div>
<div class="tab-pane fade" id="ipv6" role="tabpanel" aria-labelledby="ipv6-tab">
<div class="result-summary" id="ipv6Summary"></div>
<div id="ipv6Records"></div>
</div>
<div class="tab-pane fade" id="ns" role="tabpanel" aria-labelledby="ns-tab">