Spaces:
jiome
/
Running

nagose commited on
Commit
fdbbc8e
·
verified ·
1 Parent(s): 923f876

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +88 -58
index.js CHANGED
@@ -1,69 +1,99 @@
1
- const express = require('express');
2
- const fetch = require('node-fetch');
3
- const sharp = require('sharp');
4
 
5
  const app = express();
 
6
 
7
- // 全局变量:存储最近的日志信息
8
- const logs = [];
9
-
10
- // 重写 console.log 方法
11
- const originalConsoleLog = console.log;
12
- console.log = (...args) => {
13
- const logEntry = `${new Date().toISOString()} - ${args.join(' ')}`;
14
- logs.push(logEntry);
15
- if (logs.length > 100) {
16
- logs.shift(); // 保持日志数量不超过100条
17
- }
18
- originalConsoleLog.apply(console, args);
19
- };
20
-
21
- app.get('/resize', async (req, res) => {
22
- const imageUrl = req.query.q;
23
-
24
- if (!imageUrl) {
25
- console.error('没有提供图像 URL');
26
- return res.status(400).send('没有提供图像 URL');
27
- }
28
-
29
- console.log('原始图像URL:', imageUrl);
30
- console.log('访问来源站点:', req.headers.referer || '直接访问');
31
-
32
- try {
33
- const response = await fetch(imageUrl);
34
- if (!response.ok) {
35
- throw new Error(`获取图像失败: ${response.statusText}`);
36
  }
37
- const imageBuffer = await response.buffer();
38
- //console.log('原始图像大小:', imageBuffer.byteLength);
39
 
40
- // 使用 sharp 库来调整图像大小
41
- const resizedImageBuffer = await sharp(imageBuffer).resize(100).toBuffer();
42
- //console.log('压缩后的图像大小:', resizedImageBuffer.byteLength);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- // 将压缩后的图像转换为 Base64 编码的数据
45
- const base64Image = resizedImageBuffer.toString('base64');
 
 
 
 
 
 
 
 
46
 
47
- res.setHeader('Content-Type', 'text/plain');
48
- res.setHeader('Access-Control-Allow-Origin', '*');
49
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
50
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
51
- res.setHeader('Access-Control-Max-Age', '86400');
52
- res.send(base64Image);
53
- } catch (error) {
54
- //console.error('压缩图像时出错:', error);
55
- res.status(500).send('压缩图像时出错');
56
- }
57
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- // 新增的 /log 路由
60
- app.get('/log', (req, res) => {
61
- const recentLogs = logs.join('\n');
62
- res.setHeader('Content-Type', 'text/plain');
63
- res.send(recentLogs);
64
  });
65
 
66
- const PORT = process.env.PORT || 7860;
67
- app.listen(PORT, () => {
68
- console.log(`Server is running on port ${PORT}`);
69
  });
 
1
+ import express from "express";
2
+ import { existsSync, mkdirSync } from "fs";
 
3
 
4
  const app = express();
5
+ const port = 7860;
6
 
7
+ (() => {
8
+ if (!existsSync(`${__dirname}/iiptest`)) {
9
+ mkdirSync(`${__dirname}/iiptest`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  }
11
+ })();
 
12
 
13
+ const isipok = async (ip) => {
14
+ const ret = await fetch("https://copilot.microsoft.com/", {
15
+ headers: {
16
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
17
+ "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
18
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0",
19
+ "X-forwarded-for": ip
20
+ }
21
+ });
22
+ if (!ret.ok) {
23
+ return { ip, status: false };
24
+ }
25
+ const txt = await ret.text();
26
+ if (txt.indexOf("studiostaticassetsprod.azureedge.net/bundle-cmc/assets/bundle.js") >= 0) {
27
+ return { ip, status: false, reason: "nononononon" };
28
+ }
29
+ if (txt.indexOf('<div class="title" role="heading" aria-level="1">登录以体验 Microsoft Copilot</div>') >= 0) {
30
+ return { ip, status: false, reason: "ddddddddddd" };
31
+ }
32
 
33
+ const rt = /Region:"(.*?)"/.exec(txt);
34
+ if (!rt) {
35
+ return { ip, status: false };
36
+ }
37
+ const rg = rt[1];
38
+ if (!rg) {
39
+ return { ip, status: false };
40
+ }
41
+ return { ip, status: true, region: rg };
42
+ }
43
 
44
+ const testAll = async (i, i0, i1, i2) => {
45
+ const results = [];
46
+ const testNext = async () => {
47
+ i2++;
48
+ if (i2 > 255) {
49
+ i2 = 1;
50
+ i1++;
51
+ }
52
+ if (i1 > 255) {
53
+ i1 = 1;
54
+ i0++;
55
+ }
56
+ if (i0 > 255) {
57
+ i0 = 1;
58
+ i++;
59
+ }
60
+ if (i > 255) {
61
+ return false;
62
+ }
63
+ const XForwardedForIP = `${i}.${i0}.${i1}.${i2}`;
64
+ try {
65
+ const result = await isipok(XForwardedForIP);
66
+ results.push(result);
67
+ } catch (error) {
68
+ console.error(error);
69
+ }
70
+ return true;
71
+ }
72
+ let count = 0;
73
+ let stop = false;
74
+ while (true) {
75
+ while (count >= 16) {
76
+ await new Promise((t) => { setTimeout(t, 100) });
77
+ }
78
+ count++;
79
+ testNext().then((rt) => {
80
+ count--;
81
+ if (!rt) {
82
+ stop = true;
83
+ }
84
+ });
85
+ if (stop) {
86
+ break;
87
+ }
88
+ }
89
+ return results;
90
+ }
91
 
92
+ app.get("/test-ips", async (req, res) => {
93
+ const results = await testAll(104, 28, 1, 1);
94
+ res.json(results);
 
 
95
  });
96
 
97
+ app.listen(port, () => {
98
+ console.log(`Server is running at http://localhost:${port}`);
 
99
  });