Update index.js
Browse files
index.js
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
import express from "express";
|
|
|
2 |
|
3 |
const app = express();
|
4 |
const port = 7860;
|
5 |
|
|
|
|
|
6 |
const isipok = async (ip) => {
|
7 |
const ret = await fetch("https://copilot.microsoft.com/", {
|
8 |
headers: {
|
@@ -34,25 +37,28 @@ const isipok = async (ip) => {
|
|
34 |
return { ip, status: true, region: rg };
|
35 |
}
|
36 |
|
37 |
-
const testAll = async (
|
38 |
const results = [];
|
|
|
|
|
|
|
|
|
|
|
39 |
const testNext = async () => {
|
40 |
i2++;
|
41 |
if (i2 > 255) {
|
42 |
-
|
43 |
-
|
44 |
-
// i1++;
|
45 |
}
|
46 |
if (i1 > 255) {
|
47 |
-
|
48 |
-
|
49 |
-
// i0++;
|
50 |
}
|
51 |
if (i0 > 255) {
|
52 |
-
i0 =
|
53 |
i++;
|
54 |
}
|
55 |
-
if (i >
|
56 |
return false;
|
57 |
}
|
58 |
const XForwardedForIP = `${i}.${i0}.${i1}.${i2}`;
|
@@ -64,6 +70,7 @@ const testAll = async (i, i0, i1, i2) => {
|
|
64 |
}
|
65 |
return true;
|
66 |
}
|
|
|
67 |
let count = 0;
|
68 |
let stop = false;
|
69 |
while (true) {
|
@@ -84,11 +91,63 @@ const testAll = async (i, i0, i1, i2) => {
|
|
84 |
return results;
|
85 |
}
|
86 |
|
87 |
-
app.
|
88 |
-
const
|
|
|
89 |
res.json(results);
|
90 |
});
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
app.listen(port, () => {
|
93 |
console.log(`Server is running at http://localhost:${port}`);
|
94 |
-
});
|
|
|
1 |
import express from "express";
|
2 |
+
import bodyParser from "body-parser";
|
3 |
|
4 |
const app = express();
|
5 |
const port = 7860;
|
6 |
|
7 |
+
app.use(bodyParser.json());
|
8 |
+
|
9 |
const isipok = async (ip) => {
|
10 |
const ret = await fetch("https://copilot.microsoft.com/", {
|
11 |
headers: {
|
|
|
37 |
return { ip, status: true, region: rg };
|
38 |
}
|
39 |
|
40 |
+
const testAll = async (startIP, endIP) => {
|
41 |
const results = [];
|
42 |
+
const [startI, startI0, startI1, startI2] = startIP.split('.').map(Number);
|
43 |
+
const [endI, endI0, endI1, endI2] = endIP.split('.').map(Number);
|
44 |
+
|
45 |
+
let i = startI, i0 = startI0, i1 = startI1, i2 = startI2;
|
46 |
+
|
47 |
const testNext = async () => {
|
48 |
i2++;
|
49 |
if (i2 > 255) {
|
50 |
+
i2 = 0;
|
51 |
+
i1++;
|
|
|
52 |
}
|
53 |
if (i1 > 255) {
|
54 |
+
i1 = 0;
|
55 |
+
i0++;
|
|
|
56 |
}
|
57 |
if (i0 > 255) {
|
58 |
+
i0 = 0;
|
59 |
i++;
|
60 |
}
|
61 |
+
if (i > endI || (i === endI && i0 > endI0) || (i === endI && i0 === endI0 && i1 > endI1) || (i === endI && i0 === endI0 && i1 === endI1 && i2 > endI2)) {
|
62 |
return false;
|
63 |
}
|
64 |
const XForwardedForIP = `${i}.${i0}.${i1}.${i2}`;
|
|
|
70 |
}
|
71 |
return true;
|
72 |
}
|
73 |
+
|
74 |
let count = 0;
|
75 |
let stop = false;
|
76 |
while (true) {
|
|
|
91 |
return results;
|
92 |
}
|
93 |
|
94 |
+
app.post("/test", async (req, res) => {
|
95 |
+
const { startIP, endIP } = req.body;
|
96 |
+
const results = await testAll(startIP, endIP);
|
97 |
res.json(results);
|
98 |
});
|
99 |
|
100 |
+
app.get("/", (req, res) => {
|
101 |
+
res.send(`
|
102 |
+
<!DOCTYPE html>
|
103 |
+
<html lang="zh-CN">
|
104 |
+
<head>
|
105 |
+
<meta charset="UTF-8">
|
106 |
+
<title>IP Range Checker</title>
|
107 |
+
</head>
|
108 |
+
<body>
|
109 |
+
<h1>IP Range Checker</h1>
|
110 |
+
<form id="ipForm">
|
111 |
+
<label for="startIP">开始地址:</label>
|
112 |
+
<input type="text" id="startIP" name="startIP" required>
|
113 |
+
<br>
|
114 |
+
<label for="endIP">结束地址:</label>
|
115 |
+
<input type="text" id="endIP" name="endIP" required>
|
116 |
+
<br>
|
117 |
+
<button type="submit">检查</button>
|
118 |
+
</form>
|
119 |
+
<h2>结果:</h2>
|
120 |
+
<textarea id="results" rows="10" cols="50"></textarea>
|
121 |
+
<br>
|
122 |
+
<button id="copyButton">复制</button>
|
123 |
+
|
124 |
+
<script>
|
125 |
+
document.getElementById('ipForm').addEventListener('submit', async (event) => {
|
126 |
+
event.preventDefault();
|
127 |
+
const startIP = document.getElementById('startIP').value;
|
128 |
+
const endIP = document.getElementById('endIP').value;
|
129 |
+
const response = await fetch('/test', {
|
130 |
+
method: 'POST',
|
131 |
+
headers: {
|
132 |
+
'Content-Type': 'application/json'
|
133 |
+
},
|
134 |
+
body: JSON.stringify({ startIP, endIP })
|
135 |
+
});
|
136 |
+
const results = await response.json();
|
137 |
+
document.getElementById('results').value = JSON.stringify(results, null, 2);
|
138 |
+
});
|
139 |
+
|
140 |
+
document.getElementById('copyButton').addEventListener('click', () => {
|
141 |
+
const results = document.getElementById('results');
|
142 |
+
results.select();
|
143 |
+
document.execCommand('copy');
|
144 |
+
});
|
145 |
+
</script>
|
146 |
+
</body>
|
147 |
+
</html>
|
148 |
+
`);
|
149 |
+
});
|
150 |
+
|
151 |
app.listen(port, () => {
|
152 |
console.log(`Server is running at http://localhost:${port}`);
|
153 |
+
});
|