forked from cmliu/CF-Workers-CheckProxyIP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_worker.js
More file actions
1830 lines (1605 loc) · 67.7 KB
/
_worker.js
File metadata and controls
1830 lines (1605 loc) · 67.7 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
import { connect } from "cloudflare:sockets";
let 临时TOKEN, 永久TOKEN;
export default {
async fetch(request, env, ctx) {
const 网站图标 = env.ICO || 'https://cf-assets.www.cloudflare.com/dzlvafdwdttg/19kSkLSfWtDcspvQI5pit4/c5630cf25d589a0de91978ca29486259/performance-acceleration-bolt.svg';
const url = new URL(request.url);
const UA = request.headers.get('User-Agent') || 'null';
const path = url.pathname;
const hostname = url.hostname;
const currentDate = new Date();
const timestamp = Math.ceil(currentDate.getTime() / (1000 * 60 * 31)); // 每31分钟一个时间戳
临时TOKEN = await 双重哈希(url.hostname + timestamp + UA);
永久TOKEN = env.TOKEN || 临时TOKEN;
// 不区分大小写检查路径
if (path.toLowerCase() === '/check') {
if (!url.searchParams.has('proxyip')) return new Response('Missing proxyip parameter', { status: 400 });
if (url.searchParams.get('proxyip') === '') return new Response('Invalid proxyip parameter', { status: 400 });
if (!url.searchParams.get('proxyip').includes('.') && !(url.searchParams.get('proxyip').includes('[') && url.searchParams.get('proxyip').includes(']'))) return new Response('Invalid proxyip format', { status: 400 });
if (env.TOKEN) {
if (!url.searchParams.has('token') || url.searchParams.get('token') !== 永久TOKEN) {
return new Response(JSON.stringify({
status: "error",
message: `ProxyIP查询失败: 无效的TOKEN`,
timestamp: new Date().toISOString()
}, null, 4), {
status: 403,
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
}
}
// 获取参数中的IP或使用默认IP
const proxyIP = url.searchParams.get('proxyip').toLowerCase();
const colo = request.cf?.colo || 'CF';
// 调用CheckProxyIP函数
const result = await CheckProxyIP(proxyIP, colo);
// 返回JSON响应,根据检查结果设置不同的状态码
return new Response(JSON.stringify(result, null, 2), {
status: result.success ? 200 : 502,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
});
} else if (path.toLowerCase() === '/resolve') {
if (!url.searchParams.has('token') || (url.searchParams.get('token') !== 临时TOKEN) && (url.searchParams.get('token') !== 永久TOKEN)) {
return new Response(JSON.stringify({
status: "error",
message: `域名查询失败: 无效的TOKEN`,
timestamp: new Date().toISOString()
}, null, 4), {
status: 403,
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
}
if (!url.searchParams.has('domain')) return new Response('Missing domain parameter', { status: 400 });
const domain = url.searchParams.get('domain');
try {
const ips = await resolveDomain(domain);
return new Response(JSON.stringify({ success: true, domain, ips }), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
});
} catch (error) {
return new Response(JSON.stringify({ success: false, error: error.message }), {
status: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
});
}
} else if (path.toLowerCase() === '/ip-info') {
if (!url.searchParams.has('token') || (url.searchParams.get('token') !== 临时TOKEN) && (url.searchParams.get('token') !== 永久TOKEN)) {
return new Response(JSON.stringify({
status: "error",
message: `IP查询失败: 无效的TOKEN`,
timestamp: new Date().toISOString()
}, null, 4), {
status: 403,
headers: {
"content-type": "application/json; charset=UTF-8",
'Access-Control-Allow-Origin': '*'
}
});
}
let 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': '*'
}
});
}
if (ip.includes('[')) {
ip = ip.replace('[', '').replace(']', '');
}
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': '*'
}
});
}
} else {
const envKey = env.URL302 ? 'URL302' : (env.URL ? 'URL' : null);
if (envKey) {
const URLs = await 整理(env[envKey]);
const URL = URLs[Math.floor(Math.random() * URLs.length)];
return envKey === 'URL302' ? Response.redirect(URL, 302) : fetch(new Request(URL, request));
} else if (env.TOKEN) {
return new Response(await nginx(), {
headers: {
'Content-Type': 'text/html; charset=UTF-8',
},
});
} else if (path.toLowerCase() === '/favicon.ico') {
return Response.redirect(网站图标, 302);
}
// 直接返回HTML页面,路径解析交给前端处理
return await HTML(hostname, 网站图标);
}
}
};
// 修改后的 resolveDomain 函数 (使用 AliDNS 阿里公共DNS)
async function resolveDomain(domain) {
// 1. 去除端口号(如果存在)
domain = domain.includes(':') ? domain.split(':')[0] : domain;
try {
// 2. 使用 AliDNS (dns.alidns.com)
// 相比 Google DNS,阿里 DNS 在全球(特别是针对国内优化线路)的解析响应通常更快且稳定
const [ipv4Response, ipv6Response] = await Promise.all([
fetch(`https://dns.alidns.com/resolve?name=${domain}&type=A`, {
headers: { 'Accept': 'application/dns-json' }
}),
fetch(`https://dns.alidns.com/resolve?name=${domain}&type=AAAA`, {
headers: { 'Accept': 'application/dns-json' }
})
]);
// 3. 检查 HTTP 状态码 (防止 404/500/400 错误导致 JSON 解析崩溃)
if (!ipv4Response.ok || !ipv6Response.ok) {
throw new Error(`DNS API error: IPv4(${ipv4Response.status}) / IPv6(${ipv6Response.status})`);
}
const [ipv4Data, ipv6Data] = await Promise.all([
ipv4Response.json(),
ipv6Response.json()
]);
const ips = [];
// 4. 解析 IPv4 (type 1)
if (ipv4Data.Answer) {
const ipv4Addresses = ipv4Data.Answer
.filter(record => record.type === 1)
.map(record => record.data);
ips.push(...ipv4Addresses);
}
// 5. 解析 IPv6 (type 28)
if (ipv6Data.Answer) {
const ipv6Addresses = ipv6Data.Answer
.filter(record => record.type === 28)
.map(record => `[${record.data}]`);
ips.push(...ipv6Addresses);
}
// 6. 结果校验
if (ips.length === 0) {
// 检查 Authority 字段 (域名存在但无记录)
if (ipv4Data.Authority || ipv6Data.Authority) {
throw new Error('域名存在但没有 A/AAAA 记录');
}
throw new Error('未找到 A 或 AAAA 记录');
}
return ips;
} catch (error) {
// 7. 错误捕获,防止 Worker 直接挂掉
// console.error(`Resolve Error for ${domain}:`, error); // 调试时可开启
throw new Error(`DNS解析失败: ${error.message}`);
}
}
async function CheckProxyIP(proxyIP, colo = 'CF') {
let portRemote = 443;
if (proxyIP.includes('.tp')) {
const portMatch = proxyIP.match(/\.tp(\d+)\./);
if (portMatch) portRemote = parseInt(portMatch[1]);
} else if (proxyIP.includes('[') && proxyIP.includes(']:')) {
portRemote = parseInt(proxyIP.split(']:')[1]);
proxyIP = proxyIP.split(']:')[0] + ']';
} else if (proxyIP.includes(':')) {
portRemote = parseInt(proxyIP.split(':')[1]);
proxyIP = proxyIP.split(':')[0];
}
const tcpSocket = connect({
hostname: proxyIP,
port: portRemote,
});
try {
// 构建HTTP GET请求
const httpRequest =
"GET /cdn-cgi/trace HTTP/1.1\r\n" +
"Host: speed.cloudflare.com\r\n" +
"User-Agent: CheckProxyIP/cmliu\r\n" +
"Connection: close\r\n\r\n";
// 发送HTTP请求
const writer = tcpSocket.writable.getWriter();
await writer.write(new TextEncoder().encode(httpRequest));
writer.releaseLock();
// 读取HTTP响应
const reader = tcpSocket.readable.getReader();
let responseData = new Uint8Array(0);
let receivedData = false;
// 读取所有可用数据
while (true) {
const { value, done } = await Promise.race([
reader.read(),
new Promise(resolve => setTimeout(() => resolve({ done: true }), 5000)) // 5秒超时
]);
if (done) break;
if (value) {
receivedData = true;
// 合并数据
const newData = new Uint8Array(responseData.length + value.length);
newData.set(responseData);
newData.set(value, responseData.length);
responseData = newData;
// 检查是否接收到完整响应
const responseText = new TextDecoder().decode(responseData);
if (responseText.includes("\r\n\r\n") &&
(responseText.includes("Connection: close") || responseText.includes("content-length"))) {
break;
}
}
}
reader.releaseLock();
// 解析HTTP响应
const responseText = new TextDecoder().decode(responseData);
const statusMatch = responseText.match(/^HTTP\/\d\.\d\s+(\d+)/i);
const statusCode = statusMatch ? parseInt(statusMatch[1]) : null;
// 判断是否成功
function isValidProxyResponse(responseText, responseData) {
const statusMatch = responseText.match(/^HTTP\/\d\.\d\s+(\d+)/i);
const statusCode = statusMatch ? parseInt(statusMatch[1]) : null;
const looksLikeCloudflare = responseText.includes("cloudflare") && responseText.includes("CF-RAY");
const isExpectedError = responseText.includes("The plain HTTP request was sent to HTTPS port") && responseText.includes("400 Bad Request");
const hasBody = responseData.length > 100;
return statusCode !== null && looksLikeCloudflare && isExpectedError && hasBody;
}
// 关闭连接
await tcpSocket.close();
const isSuccessful = isValidProxyResponse(responseText, responseData);
if (isSuccessful) {
console.log(`成功通过ProxyIP ${proxyIP}:${portRemote} 连接到Cloudflare,状态码: ${statusCode} 响应内容: ${responseText}`);
const tls握手 = await 验证反代IP(proxyIP, portRemote);
// 构建JSON响应
const jsonResponse = {
success: tls握手[0],
proxyIP: proxyIP,
portRemote: portRemote,
colo: colo,
responseTime: tls握手[2] ? tls握手[2] : -1,
message: tls握手[1],
timestamp: new Date().toISOString(),
};
return jsonResponse;
} else {
console.log(`无法通过ProxyIP ${proxyIP}:${portRemote} 访问Cloudflare,状态码: ${statusCode} 响应内容: ${responseText}`);
return {
success: false,
proxyIP: proxyIP,
portRemote: portRemote,
colo: colo,
responseTime: -1,
message: "无法通过ProxyIP访问Cloudflare",
timestamp: new Date().toISOString()
};
}
} catch (error) {
// 连接失败,返回失败的JSON
return {
success: false,
proxyIP: -1,
portRemote: -1,
colo: colo,
responseTime: -1,
message: error.message || error.toString(),
timestamp: new Date().toISOString()
};
}
}
async function 整理(内容) {
var 替换后的内容 = 内容.replace(/[\r\n]+/g, '|').replace(/\|+/g, '|');
const 地址数组 = 替换后的内容.split('|');
const 整理数组 = 地址数组.filter((item, index) => {
return item !== '' && 地址数组.indexOf(item) === index;
});
return 整理数组;
}
async function 双重哈希(文本) {
const 编码器 = new TextEncoder();
const 第一次哈希 = await crypto.subtle.digest('MD5', 编码器.encode(文本));
const 第一次哈希数组 = Array.from(new Uint8Array(第一次哈希));
const 第一次十六进制 = 第一次哈希数组.map(字节 => 字节.toString(16).padStart(2, '0')).join('');
const 第二次哈希 = await crypto.subtle.digest('MD5', 编码器.encode(第一次十六进制.slice(7, 27)));
const 第二次哈希数组 = Array.from(new Uint8Array(第二次哈希));
const 第二次十六进制 = 第二次哈希数组.map(字节 => 字节.toString(16).padStart(2, '0')).join('');
return 第二次十六进制.toLowerCase();
}
async function 验证反代IP(反代IP地址, 指定端口) {
const 最大重试次数 = 4;
let 最后错误 = null;
const 开始时间 = performance.now();
// 对于连接级别的重试,每次都重新建立连接
for (let 重试次数 = 0; 重试次数 < 最大重试次数; 重试次数++) {
let TCP接口 = null;
let 传输数据 = null;
let 读取数据 = null;
try {
// 每次重试都重新建立连接
const 连接超时 = 1000 + (重试次数 * 500); // 递增超时时间
TCP接口 = await 带超时连接({ hostname: 反代IP地址, port: 指定端口 }, 连接超时);
传输数据 = TCP接口.writable.getWriter();
读取数据 = TCP接口.readable.getReader();
// 发送TLS握手
await 传输数据.write(构建TLS握手());
// 读取响应,超时时间也递增
const 读取超时 = 连接超时;
const { value: 返回数据, 超时 } = await 带超时读取(读取数据, 读取超时);
if (超时) {
最后错误 = `第${重试次数 + 1}次重试:读取响应超时`;
throw new Error(最后错误);
}
if (!返回数据 || 返回数据.length === 0) {
最后错误 = `第${重试次数 + 1}次重试:未收到任何响应数据`;
throw new Error(最后错误);
}
// 检查TLS响应
if (返回数据[0] === 0x16) {
// 成功,清理资源
try {
读取数据.cancel();
TCP接口.close();
} catch (cleanupError) {
console.log('清理资源时出错:', cleanupError);
}
return [true, `第${重试次数 + 1}次验证有效ProxyIP`, Math.round(performance.now() - 开始时间)];
} else {
最后错误 = `第${重试次数 + 1}次重试:收到非TLS响应(0x${返回数据[0].toString(16).padStart(2, '0')})`;
throw new Error(最后错误);
}
} catch (error) {
// 记录具体错误
最后错误 = `第${重试次数 + 1}次重试失败: ${error.message || error.toString()}`;
// 判断是否应该继续重试
const 错误信息 = error.message || error.toString();
const 不应重试的错误 = [
'连接被拒绝',
'Connection refused',
'网络不可达',
'Network unreachable',
'主机不可达',
'Host unreachable'
];
const 应该停止重试 = 不应重试的错误.some(errorPattern =>
错误信息.toLowerCase().includes(errorPattern.toLowerCase())
);
if (应该停止重试) {
最后错误 = `连接失败,无需重试: ${错误信息}`;
break; // 跳出重试循环
}
} finally {
// 确保每次重试后都清理资源
try {
if (读取数据) {
读取数据.cancel();
}
if (TCP接口) {
TCP接口.close();
}
} catch (cleanupError) {
console.log('清理资源时出错:', cleanupError);
}
// 等待资源完全释放
await new Promise(resolve => setTimeout(resolve, 100));
}
// 如果不是最后一次重试,等待一段时间再重试
if (重试次数 < 最大重试次数 - 1) {
const 等待时间 = 200 + (重试次数 * 300); // 递增等待时间
await new Promise(resolve => setTimeout(resolve, 等待时间));
}
}
// 所有重试都失败了
return [false, 最后错误 || '连接验证失败', -1];
}
function 构建TLS握手() {
const hexStr =
'16030107a30100079f0303af1f4d78be2002cf63e8c727224cf1ee4a8ac89a0ad04bc54cbed5cd7c830880203d8326ae1d1d076ec749df65de6d21dec7371c589056c0a548e31624e121001e0020baba130113021303c02bc02fc02cc030cca9cca8c013c014009c009d002f0035010007361a1a0000000a000c000acaca11ec001d00170018fe0d00ba0000010001fc00206a2fb0535a0a5e565c8a61dcb381bab5636f1502bbd09fe491c66a2d175095370090dd4d770fc5e14f4a0e13cfd919a532d04c62eb4a53f67b1375bf237538cea180470d942bdde74611afe80d70ad25afb1d5f02b2b4eed784bc2420c759a742885f6ca982b25d0fdd7d8f618b7f7bc10172f61d446d8f8a6766f3587abbae805b8ef40fcb819194ac49e91c6c3762775f8dc269b82a21ddccc9f6f43be62323147b411475e47ea2c4efe52ef2cef5c7b32000d00120010040308040401050308050501080606010010000e000c02683208687474702f312e31000b0002010000050005010000000044cd00050003026832001b00030200020017000000230000002d000201010012000000000010000e00000b636861746770742e636f6dff01000100002b0007061a1a03040303003304ef04edcaca00010011ec04c05eac5510812e46c13826d28279b13ce62b6464e01ae1bb6d49640e57fb3191c656c4b0167c246930699d4f467c19d60dacaa86933a49e5c97390c3249db33c1aa59f47205701419461569cb01a22b4378f5f3bb21d952700f250a6156841f2cc952c75517a481112653400913f9ab58982a3f2d0010aba5ae99a2d69f6617a4220cd616de58ccbf5d10c5c68150152b60e2797521573b10413cb7a3aab25409d426a5b64a9f3134e01dc0dd0fc1a650c7aafec00ca4b4dddb64c402252c1c69ca347bb7e49b52b214a7768657a808419173bcbea8aa5a8721f17c82bc6636189b9ee7921faa76103695a638585fe678bcbb8725831900f808863a74c52a1b2caf61f1dec4a9016261c96720c221f45546ce0e93af3276dd090572db778a865a07189ae4f1a64c6dbaa25a5b71316025bd13a6012994257929d199a7d90a59285c75bd4727a8c93484465d62379cd110170073aad2a3fd947087634574315c09a7ccb60c301d59a7c37a330253a994a6857b8556ce0ac3cda4c6fe3855502f344c0c8160313a3732bce289b6bda207301e7b318277331578f370ccbcd3730890b552373afeb162c0cb59790f79559123b2d437308061608a704626233d9f73d18826e27f1c00157b792460eda9b35d48b4515a17c6125bdb96b114503c99e7043b112a398888318b956a012797c8a039a51147b8a58071793c14a3611fb0424e865f48a61cac7c43088c634161cea089921d229e1a370effc5eff2215197541394854a201a6ebf74942226573bb95710454bd27a52d444690837d04611b676269873c50c3406a79077e6606478a841f96f7b076a2230fd34f3eea301b77bf00750c28357a9df5b04f192b9c0bbf4f71891f1842482856b021280143ae74356c5e6a8e3273893086a90daa7a92426d8c370a45e3906994b8fa7a57d66b503745521e40948e83641de2a751b4a836da54f2da413074c3d856c954250b5c8332f1761e616437e527c0840bc57d522529b9259ccac34d7a3888f0aade0a66c392458cc1a698443052413217d29fbb9a1124797638d76100f82807934d58f30fcff33197fc171cfa3b0daa7f729591b1d7389ad476fde2328af74effd946265b3b81fa33066923db476f71babac30b590e05a7ba2b22f86925abca7ef8058c2481278dd9a240c8816bba6b5e6603e30670dffa7e6e3b995b0b18ec404614198a43a07897d84b439878d179c7d6895ac3f42ecb7998d4491060d2b8a5316110830c3f20a3d9a488a85976545917124c1eb6eb7314ea9696712b7bcab1cfd2b66e5a85106b2f651ab4b8a145e18ac41f39a394da9f327c5c92d4a297a0c94d1b8dcc3b111a700ac8d81c45f983ca029fd2887ad4113c7a23badf807c6d0068b4fa7148402aae15cc55971b57669a4840a22301caaec392a6ea6d46dab63890594d41545ebc2267297e3f4146073814bb3239b3e566684293b9732894193e71f3b388228641bb8be6f5847abb9072d269cb40b353b6aa3259ccb7e438d6a37ffa8cc1b7e4911575c41501321769900d19792aa3cfbe58b0aaf91c91d3b63900697279ad6c1aa44897a07d937e0d5826c24439420ca5d8a63630655ce9161e58d286fc885fcd9b19d096080225d16c89939a24aa1e98632d497b5604073b13f65bdfddc1de4b40d2a829b0521010c5f0f241b1ccc759049579db79983434fac2748829b33f001d0020a8e86c9d3958e0257c867e59c8082238a1ea0a9f2cac9e41f9b3cb0294f34b484a4a000100002900eb00c600c0afc8dade37ae62fa550c8aa50660d8e73585636748040b8e01d67161878276b1ec1ee2aff7614889bb6a36d2bdf9ca097ff6d7bf05c4de1d65c2b8db641f1c8dfbd59c9f7e0fed0b8e0394567eda55173d198e9ca40883b291ab4cada1a91ca8306ca1c37e047ebfe12b95164219b06a24711c2182f5e37374d43c668d45a3ca05eda90e90e510e628b4cfa7ae880502dae9a70a8eced26ad4b3c2f05d77f136cfaa622e40eb084dd3eb52e23a9aeff6ae9018100af38acfd1f6ce5d8c53c4a61c547258002120fe93e5c7a5c9c1a04bf06858c4dd52b01875844e15582dd566d03f41133183a0';
return new Uint8Array(hexStr.match(/.{1,2}/g).map(b => parseInt(b, 16)));
}
async function 带超时连接({ hostname, port }, 超时时间) {
const TCP接口 = connect({ hostname, port });
try {
await Promise.race([
TCP接口.opened,
new Promise((_, reject) =>
setTimeout(() => reject(new Error("连接超时")), 超时时间)
),
]);
return TCP接口; // ✅ 连接成功
} catch (err) {
TCP接口.close?.(); // 确保连接关闭
throw err; // ⛔ 抛出错误由调用者处理
}
}
function 带超时读取(reader, 超时) {
return new Promise(resolve => {
const timeoutId = setTimeout(() => resolve({ done: true, value: null, 超时: true }), 超时);
reader.read().then(result => {
clearTimeout(timeoutId);
resolve({ ...result, 超时: false });
});
});
}
async function nginx() {
const text = `
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
`
return text;
}
async function HTML(hostname, 网站图标) {
// 首页 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>Check ProxyIP - 代理IP检测服务</title>
<link rel="icon" href="${网站图标}" type="image/x-icon">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #3498db;
--primary-dark: #2980b9;
--secondary-color: #1abc9c;
--success-color: #2ecc71;
--warning-color: #f39c12;
--error-color: #e74c3c;
--bg-primary: #ffffff;
--bg-secondary: #f8f9fa;
--bg-tertiary: #e9ecef;
--text-primary: #2c3e50;
--text-secondary: #6c757d;
--text-light: #adb5bd;
--border-color: #dee2e6;
--shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
--shadow-md: 0 4px 6px rgba(0,0,0,0.1);
--shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
--border-radius: 12px;
--border-radius-sm: 8px;
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6;
color: var(--text-primary);
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
position: relative;
overflow-x: hidden;
}
.container {
max-width: 1000px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
margin-bottom: 50px;
animation: fadeInDown 0.8s ease-out;
}
.main-title {
font-size: clamp(2.5rem, 5vw, 4rem);
font-weight: 700;
background: linear-gradient(135deg, #ffffff 0%, #f0f0f0 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 16px;
text-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.subtitle {
font-size: 1.2rem;
color: rgba(255,255,255,0.9);
font-weight: 400;
margin-bottom: 8px;
}
.badge {
display: inline-block;
background: rgba(255,255,255,0.2);
backdrop-filter: blur(10px);
padding: 8px 16px;
border-radius: 50px;
color: white;
font-size: 0.9rem;
font-weight: 500;
border: 1px solid rgba(255,255,255,0.3);
}
.card {
background: var(--bg-primary);
border-radius: var(--border-radius);
padding: 32px;
box-shadow: var(--shadow-lg);
margin-bottom: 32px;
border: 1px solid var(--border-color);
transition: var(--transition);
animation: fadeInUp 0.8s ease-out;
backdrop-filter: blur(20px);
position: relative;
overflow: hidden;
}
.card::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
}
.card:hover {
transform: translateY(-4px);
box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}
.form-section {
margin-bottom: 32px;
}
.form-label {
display: block;
font-weight: 600;
font-size: 1.1rem;
margin-bottom: 12px;
color: var(--text-primary);
}
.input-group {
display: flex;
gap: 16px;
align-items: flex-end;
flex-wrap: wrap;
}
.input-wrapper {
flex: 1;
min-width: 300px;
position: relative;
}
.form-input {
width: 100%;
padding: 16px 20px;
border: 2px solid var(--border-color);
border-radius: var(--border-radius-sm);
font-size: 16px;
font-family: inherit;
transition: var(--transition);
background: var(--bg-primary);
color: var(--text-primary);
}
.form-input:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.1);
transform: translateY(-1px);
}
.form-input::placeholder {
color: var(--text-light);
}
.btn {
padding: 16px 32px;
border: none;
border-radius: var(--border-radius-sm);
font-size: 16px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
transition: var(--transition);
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-width: 120px;
position: relative;
overflow: hidden;
}
.btn::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
transition: left 0.6s;
}
.btn:hover::before {
left: 100%;
}
.btn-primary {
background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
color: white;
box-shadow: var(--shadow-md);
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(52, 152, 219, 0.3);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-primary:disabled {
background: var(--text-light);
cursor: not-allowed;
transform: none;
box-shadow: var(--shadow-sm);
}
.btn-loading {
pointer-events: none;
}
.loading-spinner {
width: 20px;
height: 20px;
border: 2px solid rgba(255,255,255,0.3);
border-top: 2px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.result-section {
margin-top: 32px;
opacity: 0;
transform: translateY(20px);
transition: var(--transition);
}
.result-section.show {
opacity: 1;
transform: translateY(0);
}
.result-card {
border-radius: var(--border-radius-sm);
padding: 24px;
margin-bottom: 16px;
border-left: 4px solid;
position: relative;
overflow: hidden;
}
.result-success {
background: linear-gradient(135deg, #d4edda, #c3e6cb);
border-color: var(--success-color);
color: #155724;
}
.result-error {
background: linear-gradient(135deg, #f8d7da, #f5c6cb);
border-color: var(--error-color);
color: #721c24;
}
.result-warning {
background: linear-gradient(135deg, #fff3cd, #ffeaa7);
border-color: var(--warning-color);
color: #856404;
}
.ip-grid {
display: grid;
gap: 16px;
margin-top: 20px;
}
.ip-item {
background: rgba(255,255,255,0.9);
border: 1px solid var(--border-color);
border-radius: var(--border-radius-sm);
padding: 20px;
transition: var(--transition);
position: relative;
}
.ip-item:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-md);
}
.ip-status-line {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.status-icon {
font-size: 18px;
margin-left: auto;
}
.copy-btn {
background: var(--bg-secondary);
border: 1px solid var(--border-color);
padding: 6px 12px;
border-radius: 6px;
font-size: 14px;
cursor: pointer;
transition: var(--transition);
display: inline-flex;
align-items: center;
gap: 4px;
margin: 4px 0;
}
.copy-btn:hover {
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
.copy-btn.copied {
background: var(--success-color);
color: white;
border-color: var(--success-color);
}
.info-tags {
display: flex;
gap: 8px;
flex-wrap: wrap;
margin-top: 8px;
}
.tag {
padding: 4px 8px;
border-radius: 16px;
font-size: 12px;
font-weight: 500;
}
.tag-country {
background: #e3f2fd;
color: #1976d2;
}
.tag-as {
background: #f3e5f5;
color: #7b1fa2;
}
.api-docs {
background: var(--bg-primary);
border-radius: var(--border-radius);
padding: 32px;
box-shadow: var(--shadow-lg);
animation: fadeInUp 0.8s ease-out 0.2s both;
}
.section-title {
font-size: 1.8rem;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 24px;
position: relative;
padding-bottom: 12px;
}
.section-title::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 60px;
height: 3px;
background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
border-radius: 2px;
}
.code-block {
background: #2d3748;
color: #e2e8f0;
padding: 20px;
border-radius: var(--border-radius-sm);
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 14px;
overflow-x: auto;
margin: 16px 0;
border: 1px solid #4a5568;
position: relative;
}
.code-block::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 2px;
background: linear-gradient(90deg, #48bb78, #38b2ac);
}
.highlight {
color: #f56565;
font-weight: 600;
}
.footer {
text-align: center;
padding: 20px 20px 20px;
color: rgba(255,255,255,0.8);
font-size: 14px;
margin-top: 40px;
border-top: 1px solid rgba(255,255,255,0.1);
}
.github-corner {
position: fixed;
top: 0;
right: 0;
z-index: 1000;
transition: var(--transition);
}
.github-corner:hover {
transform: scale(1.1);
}
.github-corner svg {
fill: rgba(255,255,255,0.9);
color: var(--primary-color);
width: 80px;
height: 80px;
filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));