检测工具能做什么
proxy-probe.mjs 从链接或文件读取列表,通过每一行请求 judge 页面,也就是返回所收到请求头的网站。judge 的响应给出代理的三个事实:是否可用、请求用了多久、网站看到了哪个 IP。
- 行格式:
ip:port、host:port:login:password和login:password@host:port。前缀http://或socks5://设置单独一行的协议。 - 包含冒号或 @ 的密码也能正确解析。脚本会删除重复项,跳过空行和格式不符的行。
- 脚本同时检测 150 个代理,每个最多等待 8 秒,所以一千行一分钟内可以完成。这两个数字都可以用参数修改。
- 每个可用代理都会得到匿名级别评分:high、medium 或 none。
- 响应了但拒绝登录名或密码的代理会进入单独的计数,不算失效。
- 可用的行按原样、从快到慢写入
alive.txt,文件可以直接交给程序使用。参数--csv会增加一份报告,包含延迟、出口 IP 和匿名级别。
需要 Node.js 18 或更新版本。没有第三方包,只用内置模块,全部代码在一个文件里。列表不会发送到别处:脚本只连接列表中的代理和 judge 页面。
一条命令下载并运行
文件直链:
下载 proxy-probe.mjshttps://proxymix.net/res/files/proxy-probe.mjs
Linux 和 macOS:命令把文件下载到当前文件夹并立即开始检测。
wget -qO proxy-probe.mjs https://proxymix.net/res/files/proxy-probe.mjs && node proxy-probe.mjs list.txt如果服务器没有 wget,可以用 curl:
curl -fsSLo proxy-probe.mjs https://proxymix.net/res/files/proxy-probe.mjs && node proxy-probe.mjs list.txt不保存文件:curl 把脚本直接传给 Node,参数放在连字符之后。
curl -fsSL https://proxymix.net/res/files/proxy-probe.mjs | node --input-type=module - list.txt把 list.txt 换成您的文件或列表链接。
运行方式
不限流量套餐:面板中 ip:port 列表的链接,末尾不要加 .csv,检测工具不读取表格。请让 --parallel 低于套餐线程数,否则多余的连接会被拒绝,可用的行也会算作失效。
node proxy-probe.mjs "https://YOUR_LIST_LINK" --parallel 100按 GB 计费的套餐:包含 host:port:login:password 行的文件。SOCKS5 行请用 --kind socks5 检测。
node proxy-probe.mjs http-lines.txt
node proxy-probe.mjs socks-lines.txt --kind socks5免费代理:长列表里有很多失效行。请提高并行数,缩短等待时间,并只保留报告中评分为 high 的行。
node proxy-probe.mjs free.txt --parallel 400 --wait 4 --csv report.csv
grep ',high$' report.csv | cut -d, -f1 > high.txt用于表格的报告:CSV 可以在 Excel 和 Google 表格中打开,列为 proxy、ms、exit_ip、anonymity。
node proxy-probe.mjs list.txt --output ok.txt --csv report.csv如果 httpbin.org 响应慢或在您的网络中被封锁,可以用自己的 judge 页面。任何能打印请求头的普通 http 地址都可以。
node proxy-probe.mjs list.txt --judge http://YOUR_SERVER/headers脚本输出什么
检测进度以一行不断更新的文字输出到 stderr。脚本在 stdout 输出最快的 15 个代理及其延迟、出口 IP 和评分,最后一行是可用数量。下面是检测 38 个免费 SOCKS5 代理的样子,地址已替换为示例:
$ node proxy-probe.mjs socks.txt --kind socks5 --csv report.csv
checking 38 proxies, 150 at a time, via httpbin.org
38/38 checked, 25 alive
198.51.100.17:1088 3497 ms 203.0.113.40 high
192.0.2.63:10461 3667 ms 198.51.100.86 high
203.0.113.109:13391 3844 ms 192.0.2.132 high
198.51.100.155:38182 3954 ms 198.51.100.155 high
203.0.113.178:80 4170 ms 203.0.113.178 high
192.0.2.201:16209 4240 ms 198.51.100.224 high
203.0.113.247:1080 4327 ms 203.0.113.247 high
192.0.2.20:1080 4340 ms 198.51.100.43 high
203.0.113.66:1026 4494 ms 192.0.2.89 high
203.0.113.66:1059 4572 ms 192.0.2.89 high
203.0.113.66:1045 4654 ms 192.0.2.89 high
203.0.113.66:1087 4666 ms 198.51.100.112 high
203.0.113.66:1099 4752 ms 198.51.100.112 high
203.0.113.135:10800 4786 ms 203.0.113.135 high
192.0.2.158:1080 4917 ms 192.0.2.158 high
25 of 38 alive, saved to alive.txtalive.txt 中的行保持列表中的原样。CSV 报告在此基础上增加测量数据:
$ head -3 alive.txt
198.51.100.17:1088
192.0.2.63:10461
203.0.113.109:13391
$ head -4 report.csv
proxy,ms,exit_ip,anonymity
198.51.100.17:1088,3497,203.0.113.40,high
192.0.2.63:10461,3667,198.51.100.86,high
203.0.113.109:13391,3844,192.0.2.132,high在全新服务器上安装 Node.js
先用 node -v 检查版本:v18 及更新版本都可以。如果没有 Node 或版本太旧,请按系统安装。下面的命令以 root 身份运行,普通用户需要在 apt、dnf 和 bash 前加 sudo。
Debian 12 和 Ubuntu 24.04:标准仓库中的 Node 即可。
apt update && apt install -y nodejs
node -vUbuntu 20.04 和 22.04、Debian 11,以及仓库中 Node 版本低于 18 的系统:使用 NodeSource 仓库的最新 LTS。
apt update && apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs
node -vAlmaLinux、Rocky Linux 和 CentOS Stream:
curl -fsSL https://rpm.nodesource.com/setup_22.x | bash -
dnf install -y nodejs
node -v在 Windows 上运行
用 Windows 10 和 11 内置的 winget 安装 Node.js LTS。安装后打开新的终端窗口,让 PATH 生效。
winget install OpenJS.NodeJS.LTS在 PowerShell 中下载脚本并开始检测:
iwr https://proxymix.net/res/files/proxy-probe.mjs -OutFile proxy-probe.mjs -UseBasicParsing; node proxy-probe.mjs list.txt在 cmd 命令提示符中可以用内置的 curl:
curl -fsSLo proxy-probe.mjs https://proxymix.net/res/files/proxy-probe.mjs && node proxy-probe.mjs list.txt把列表放在同一文件夹,或用引号写完整路径:node proxy-probe.mjs "C:\proxy\list.txt"。alive.txt 文件会出现在您运行命令的文件夹中。
定时检测
要让程序始终使用存活的代理,请用定时器运行检测工具,并把结果保存在一个固定文件中。脚本先把新列表写入临时的 fresh.txt,然后一条命令用它替换 alive.txt,所以程序不会读到写了一半的文件。如果没有代理存活,脚本以代码 1 退出,alive.txt 保留上一份列表。
Linux:把脚本放到单独的文件夹,打开 cron 调度器。
mkdir -p /opt/probe && cd /opt/probe
wget -qO proxy-probe.mjs https://proxymix.net/res/files/proxy-probe.mjs
crontab -e添加这一行:每 20 分钟检测一次,第一个副本运行时 flock 不会启动第二个,日志写入 probe.log。
*/20 * * * * cd /opt/probe && flock -n probe.lock node proxy-probe.mjs "https://YOUR_LIST_LINK" --output fresh.txt >> probe.log 2>&1 && mv fresh.txt alive.txtWindows:创建 C:\probe 文件夹,把脚本和包含两行内容的 run.cmd 文件放进去:
cd /d C:\probe
node proxy-probe.mjs "https://YOUR_LIST_LINK" --output fresh.txt >> probe.log 2>&1 && move /y fresh.txt alive.txt一条命令即可创建每 20 分钟运行一次的任务:
schtasks /create /tn "proxy-probe" /tr "C:\probe\run.cmd" /sc minute /mo 20这个任务只在您登录时运行。要让它在未登录时也运行,请以管理员身份执行命令并加上 /ru SYSTEM 参数。run.cmd 内列表链接中的 % 要写两次:%%。
在程序中把 alive.txt 设为代理文件:Linux 上是 /opt/probe/alive.txt,Windows 上是 C:\probe\alive.txt。如果程序能按定时器重新读取文件,请打开这个功能,新的行无需重启即可生效。
匿名级别如何计算
检测前,脚本直接访问 judge 并记住您自己的地址。然后把每个响应和它比较:
- high:judge 既没看到您的地址,也没看到 Via 或 X-Forwarded-For 之类的代理请求头;
- medium:您的地址被隐藏,但代理的请求头暴露了它自己;
- none:您的真实地址到达了 judge,代理只是转发流量。
ProxyMix 列表
按 GB 计费套餐的行形如 host:port:login:password:登录名已在行中,检测工具会自己传给代理。请用创建时对应的协议检测这些套餐的每一行。
检测工具请使用末尾没有 .csv 的套餐链接:不需要登录名,检测工具也不读取表格。访问权限开放给您在面板中添加的 IP,所以请从那台服务器运行检测工具。一个端口接受 HTTP、HTTPS、SOCKS4 和 SOCKS5:请用您的程序所用的协议检测。
alive.txt 中检测过的行可以直接导入 ScrapeBox、Key Collector 或 Python 代码。
退出代码和消息
- 代码 0:至少有一个代理可用。代码 1:没有可用代理,或者列表中没有代理行。
- 代码 2:参数错误,脚本打印帮助。
- “judge did not answer directly”:judge 页面不可用或对您的机器被封锁。请换一个,否则透明代理会被漏掉。
- “N of M lines with credentials were rejected”:这些代理响应了,但拒绝了登录名或密码。它们不算失效。请在服务商的面板中检查访问信息。
脚本代码
代码完全公开,请在自己的服务器上运行前先读一读。
显示 proxy-probe.mjs 代码
import net from 'node:net';
import { readFile, writeFile } from 'node:fs/promises';
const settings = {
parallel: 150,
kind: 'http',
wait: 8,
judge: 'http://httpbin.org/get',
output: 'alive.txt',
csv: '',
};
const help = `usage: node proxy-probe.mjs <list-url-or-file> [options]
list lines ip:port, host:port:login:password or login:password@host:port;
start a line with socks5:// or http:// to set its protocol,
colons and @ signs inside a password are fine
--parallel N proxies checked at the same time (150)
--kind K http or socks5 (http)
--wait S seconds per proxy (8)
--judge URL plain http page that echoes request headers (http://httpbin.org/get)
--output FILE working proxies, fastest first (alive.txt)
--csv FILE extra report: proxy, ms, exit ip, anonymity`;
const args = process.argv.slice(2);
const source = args.find((a, i) => !a.startsWith('--') && !(args[i - 1] || '').startsWith('--'));
for (let i = 0; i < args.length; i++) {
const name = args[i].startsWith('--') ? args[i].slice(2) : '';
if (name === 'help') {
console.log(help);
process.exit(0);
}
if (name in settings) settings[name] = typeof settings[name] === 'number' ? Number(args[++i]) : args[++i];
}
if (!source || !['http', 'socks5'].includes(settings.kind) || !(settings.parallel > 0) || !(settings.wait > 0)) {
console.error(help);
process.exit(2);
}
const judge = new URL(settings.judge);
const judgePort = Number(judge.port || 80);
const leakHeaders = /\b(via|x-forwarded-for|forwarded|x-real-ip|client-ip|x-proxy-id)\b/i;
const ipv4 = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
const scrub = (text) => text.split(judge.hostname).join('');
const protoPrefix = /^(http|socks5h?):\/\/(.+)$/i;
const plausible = (host) => host === 'localhost' || /^[\w-]+(\.[\w-]+)+$/.test(host);
const validPort = (port) => /^\d{1,5}$/.test(port) && Number(port) > 0 && Number(port) < 65536;
const keyed = (item) => item.login !== undefined;
const label = (item) => (keyed(item) ? `${item.login}@${item.host}:${item.port}` : item.text);
const cell = (value) => (/[",\r\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value);
const rejected = () => Object.assign(new Error('credentials rejected'), { rejected: true });
function decode(raw) {
const text = raw.trim();
const tagged = text.match(protoPrefix);
const body = tagged ? tagged[2].replace(/\/+$/, '') : text;
const kind = tagged ? (tagged[1].toLowerCase() === 'http' ? 'http' : 'socks5') : '';
const guesses = [];
const colonForm = body.match(/^([^:@]+):(\d+):([^:]*):(.*)$/);
if (colonForm) guesses.push({ host: colonForm[1], port: colonForm[2], login: colonForm[3], password: colonForm[4] });
const atForm = body.match(/^([^:]*)(?::(.*))?@([^:@]+):(\d+)$/);
if (atForm) guesses.push({ host: atForm[3], port: atForm[4], login: atForm[1], password: atForm[2] ?? '' });
const usable = guesses.filter((g) => validPort(g.port));
const best = usable.find((g) => plausible(g.host)) || usable[0];
if (best) return { text, kind, ...best, port: Number(best.port) };
if (tagged) {
const bare = body.match(/^([^:@/]+):(\d+)$/);
return bare && validPort(bare[2]) ? { text, kind, host: bare[1], port: Number(bare[2]) } : null;
}
const [host, port] = text.split(':');
return host && /^\d+$/.test(port || '') ? { text: `${host}:${port}`, kind, host, port: Number(port) } : null;
}
async function loadLines(from) {
const text = /^https?:\/\//.test(from) ? await (await fetch(from)).text() : await readFile(from, 'utf8');
const seen = new Map();
for (const raw of text.split(/\r?\n/)) {
const item = decode(raw);
if (item && !seen.has(item.text)) seen.set(item.text, item);
}
return [...seen.values()];
}
function talk(host, port) {
const sock = net.connect({ host, port: Number(port) });
let buffered = Buffer.alloc(0);
let waiter = null;
let ended = false;
const wake = () => waiter && waiter();
sock.on('data', (chunk) => { buffered = Buffer.concat([buffered, chunk]); wake(); });
sock.on('end', () => { ended = true; wake(); });
sock.on('error', () => { ended = true; wake(); });
sock.on('close', () => { ended = true; wake(); });
const take = (count) => new Promise((resolve, reject) => {
const check = () => {
if (buffered.length >= count) {
const part = buffered.subarray(0, count);
buffered = buffered.subarray(count);
waiter = null;
resolve(part);
} else if (ended) {
waiter = null;
reject(new Error('closed'));
}
};
waiter = check;
check();
});
const rest = () => new Promise((resolve) => {
const check = () => { if (ended) resolve(buffered.toString('latin1')); };
waiter = check;
check();
});
const ready = new Promise((resolve, reject) => {
sock.once('connect', resolve);
sock.once('error', reject);
sock.once('close', () => reject(new Error('closed')));
});
return { sock, take, rest, ready };
}
async function socksOpen(link, item) {
const withLogin = keyed(item);
link.sock.write(Buffer.from([5, 1, withLogin ? 2 : 0]));
const hello = await link.take(2);
if (hello[0] !== 5) throw new Error('socks reply');
if (withLogin && hello[1] === 255) throw rejected();
if (withLogin && hello[1] === 2) {
const user = Buffer.from(item.login);
const secret = Buffer.from(item.password);
if (!user.length || user.length > 255 || secret.length > 255) throw rejected();
link.sock.write(Buffer.concat([Buffer.from([1, user.length]), user, Buffer.from([secret.length]), secret]));
const ack = await link.take(2);
if (ack[1] !== 0) throw rejected();
} else if (hello[1] !== 0) {
throw new Error('socks auth');
}
const name = Buffer.from(judge.hostname);
link.sock.write(Buffer.concat([Buffer.from([5, 1, 0, 3, name.length]), name, Buffer.from([judgePort >> 8, judgePort & 255])]));
const head = await link.take(4);
if (head[1] !== 0) throw new Error('socks refused');
const tail = head[3] === 1 ? 6 : head[3] === 4 ? 18 : (await link.take(1))[0] + 2;
await link.take(tail);
}
async function probe(item) {
const kind = item.kind || settings.kind;
const started = performance.now();
const link = talk(item.host, item.port);
const timer = setTimeout(() => link.sock.destroy(), settings.wait * 1000);
try {
await link.ready;
if (kind === 'socks5') await socksOpen(link, item);
const target = kind === 'socks5' ? judge.pathname + judge.search : judge.href;
const pass = kind === 'http' && keyed(item)
? `Proxy-Authorization: Basic ${Buffer.from(`${item.login}:${item.password}`).toString('base64')}\r\n`
: '';
link.sock.write(`GET ${target} HTTP/1.1\r\nHost: ${judge.host}\r\nUser-Agent: proxy-probe\r\nAccept: */*\r\n${pass}Connection: close\r\n\r\n`);
const answer = await link.rest();
const [head, ...bodyParts] = answer.split('\r\n\r\n');
if (pass && /^HTTP\/1\.[01] 407/.test(head)) return { item, rejected: true };
if (!/^HTTP\/1\.[01] 200/.test(head)) return null;
const body = bodyParts.join('\r\n\r\n');
return { item, ms: Math.round(performance.now() - started), body };
} catch (err) {
return err.rejected ? { item, rejected: true } : null;
} finally {
clearTimeout(timer);
link.sock.destroy();
}
}
function grade(body, myIp) {
const text = scrub(body);
if (myIp && text.includes(myIp)) return 'none';
return leakHeaders.test(text) ? 'medium' : 'high';
}
let myIp = '';
try {
myIp = (scrub(await (await fetch(judge.href, { signal: AbortSignal.timeout(10000) })).text()).match(ipv4) || [''])[0];
} catch {
console.error('judge did not answer directly, anonymity will not detect transparent proxies');
}
const entries = await loadLines(source);
if (!entries.length) {
console.error('no proxy lines found in', source);
process.exit(1);
}
const withCredentials = entries.filter(keyed).length;
console.error(`checking ${entries.length} proxies${withCredentials ? ` (${withCredentials} with credentials)` : ''}, ${settings.parallel} at a time, via ${judge.host}`);
const alive = [];
const turnedAway = [];
let cursor = 0;
let done = 0;
let lastShown = 0;
const lane = async () => {
while (cursor < entries.length) {
const hit = await probe(entries[cursor++]);
done++;
if (hit && hit.rejected) {
turnedAway.push(hit.item);
} else if (hit) {
const found = scrub(hit.body).match(ipv4) || [];
const exit = found.find((ip) => ip !== myIp) || found[0] || '';
alive.push({ entry: hit.item.text, shown: label(hit.item), ms: hit.ms, exit, level: grade(hit.body, myIp) });
}
if (done - lastShown >= Math.max(1, Math.ceil(entries.length / 20)) || done === entries.length) {
lastShown = done;
const denied = turnedAway.length ? `, ${turnedAway.length} rejected credentials` : '';
process.stderr.write(`\r${done}/${entries.length} checked, ${alive.length} alive${denied} `);
}
}
};
await Promise.all(Array.from({ length: Math.min(settings.parallel, entries.length) }, lane));
process.stderr.write('\n');
alive.sort((a, b) => a.ms - b.ms);
await writeFile(settings.output, alive.map((p) => p.entry).join('\n') + (alive.length ? '\n' : ''));
if (settings.csv) {
const rows = ['proxy,ms,exit_ip,anonymity', ...alive.map((p) => `${cell(p.entry)},${p.ms},${p.exit},${p.level}`)];
await writeFile(settings.csv, rows.join('\n') + '\n');
}
const top = alive.slice(0, 15);
const width = Math.max(22, ...top.map((p) => p.shown.length));
for (const p of top) console.log(`${p.shown.padEnd(width)} ${String(p.ms).padStart(5)} ms ${p.exit.padEnd(15)} ${p.level}`);
if (turnedAway.length) {
console.log(`${turnedAway.length} of ${withCredentials} lines with credentials were rejected, first ${label(turnedAway[0])}: check the login and password`);
}
console.log(`${alive.length} of ${entries.length} alive, saved to ${settings.output}`);
process.exit(alive.length ? 0 : 1);