基于 tcptest.cn 节点资源的批量 TCPing 测试服务。Base URL: /api
/api/health)必须携带 API Key,两种方式:
方式 1: 请求头 X-API-Key: your_key 方式 2: URL 参数 ?key=your_key
GET /api/nodes
POST /api/tcping
Content-Type: application/json
{
"targets": "example.com:443\n1.1.1.1:443", // 字符串或数组
"nodes": "all", // "all"|"telecom"|"unicom"|"mobile"|"overseas"|节点key数组
"port": 443, // 默认端口(目标未带端口时生效)
"timeoutMs": 120000 // 可选,超时时间
}
| nodes 取值 | 说明 |
|---|---|
"all" | 全部 111 个节点 |
"telecom" / "unicom" / "mobile" | 电信 / 联通 / 移动 |
"overseas" | 港澳台 + 海外节点 |
[46, 399, ...] | 指定节点 key 数组 |
result 事件。请求参数与同步接口一致。POST /api/tcping/stream Accept: text/event-stream 事件流格式: event: meta → 测试元信息(目标数/节点列表) event: status → 连接状态 event: result → 单个节点结果(含 _progress 进度) event: done → 全部完成 event: error → 出错
const resp = await fetch('/api/tcping/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ targets: 'example.com:443', nodes: 'telecom', port: 443 })
});
const reader = resp.body.getReader();
// 逐块解析 SSE 事件...(前端页面即此实现)
GET /api/health → {"status":"ok","activeTests":0}
# 测 3 个目标,全部节点(同步)
curl -s -X POST http://localhost:3000/api/tcping \
-H 'Content-Type: application/json' \
-H 'X-API-Key: your_key' \
-d '{"targets":"example.com:443\n1.1.1.1","nodes":"all","port":443}'
# 只测电信节点,流式
curl -N -X POST http://localhost:3000/api/tcping/stream \
-H 'Content-Type: application/json' \
-H 'X-API-Key: your_key' \
-d '{"targets":"example.com:443","nodes":"telecom","port":443}'