普贤教程 › 包参考
netprobe 包
TCP 端口探测 / banner 读取
| 项 | 值 |
|---|---|
| 包名 | netprobe |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | netprobe.px |
| 分类 | 网络与协议 |
| 文件数 / 行数 | 1 / 183 |
安装与引入
bash
pxpkg init # 首次 pxpkg add netprobe@0.2.0 pxpkg install
px
import netprobe所属分类教程:网络与协议
公开接口
| 函数 | 参数 |
|---|---|
np_check | host, port, timeout_ms = 800 |
np_banner | host, port, timeout_ms = 800, maxlen = 256 |
np_scan | host, ports, timeout_ms = 300 |
np_ports | start, end |
其余 7 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
np_latency | host, port, timeout_ms = 800 |
np_scan_range | host, start_port, end_port, timeout_ms = 300 |
np_check_multi | hosts, port, timeout_ms = 800 |
np_summary | results |
np_port_name | port |
np_scan_named | host, ports, timeout_ms = 300 |
np_check_retry | host, port, attempts = 3, timeout_ms = 800 |
包内说明(源码头注释)
text
============================================================
普贤生态库:registry/netprobe —— TCP 端口探测 / banner 读取
------------------------------------------------------------
纯函数库(网络客户端,无并发原语),编译(px build)与解释(px run)双模式一致。
对应缺口表「网络探测(ping/端口)」的最小可实现面(ICMP 需 raw socket → 仅 TCP 探测):
np_check(host, port[, timeout_ms]) → Ok({open, err})
np_banner(host, port[, timeout_ms, maxlen]) → Ok({banner}) | Err
np_scan(host, ports[, timeout_ms]) → Ok([{port, open, err}])
np_ports(start, end) → Ok([port, ...])
实现:tcp_connect_ex(安全变体,永不杀进程)+ tcp_opt 读超时 + tcp_recv_ex。
连接失败/拒绝返回 open=false(Err 仅留给参数错误)。
============================================================
探测单端口 → Ok({open: true|false, err?})