-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck80.mjs
70 lines (57 loc) · 2.09 KB
/
check80.mjs
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
import IPCIDR from 'ip-cidr'
import fs from "fs"
import axios from 'axios';
import {JSDOM} from 'jsdom'
import {limitConcurrentRequests} from "./module/axios.mjs"
import {promisify} from "util"
const writeFileAsync = promisify(fs.writeFile);
const port = 80;
const expectedStatusCode = 403;
const htmlCheckContent = '<title>Direct IP access not allowed | Cloudflare</title>';
let iplist=[]
async function checkIP(ip) {
try {
const url = `http://${ip}:${port}`;
let response = await limitConcurrentRequests(url, { validateStatus: status => status === expectedStatusCode, timeout: 9999 });
if (response.status === expectedStatusCode) {
const dom = new JSDOM(response.data);
const document = dom.window.document;
const htmlContent = document.documentElement.innerHTML;
if (htmlContent.includes(htmlCheckContent) && (response.headers.server==undefined||"cloudflare")) {
console.log(`IP ${ip} 返回状态码为 ${expectedStatusCode},并且包含指定HTML内容`);
iplist.push(`${ip}/32\n`)
try {
//await writeFileAsync('http400ips.json', JSON.stringify(iplist, null, 2));
await writeFileAsync('data/ips.txt', iplist.join(''));
} catch (error) {
console.error('写入文件时出错:', error);
}
}
}
} catch (error) {
console.error(`无法连接到 ${ip}:${port}`);
}
}
function scanIPRange(ips){
ips.forEach(ip=>{
const cidr = new IPCIDR(ip);
const IpArray=cidr.toArray()
IpArray.forEach(checkIP)
})
}
function getIPSegmentsFromFile(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
reject(`Error reading the file: ${err}`);
return;
}
const ipSegments = data.split(/\r?\n/).filter(line => {
const ipRegex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}\/(?:[0-9]|[1-2][0-9]|3[0-2])$/;
return ipRegex.test(line);
});
resolve(ipSegments);
});
});
}
scanIPRange(await getIPSegmentsFromFile('data/testips.txt'))