A clean-room, zero-dependency local listening socket inspector for
SCORPIOX BOT. One C99 binary, three modes, no
runtime dependencies at all. It reports the TCP and UDP sockets listening on the
node it runs on, who owns them, and whether 127.0.0.1:<port> actually answers.
ports Listening TCP
Agent containers and slim BotCloud images routinely ship without ss or
netstat. Anything that shells out to them reports "no listeners" on exactly
the machines where you most want to know what is listening. This plugin parses
/proc/net/tcp, /proc/net/tcp6, /proc/net/udp and /proc/net/udp6
directly, and resolves the owning process from /proc/<pid>/fd socket inodes.
The offline test suite proves this by running the plugin with a PATH that
contains no socket tool at all - and still detecting a freshly opened listener,
with its PID and command name.
Platforms:
| Platform | Listening sockets | Owning process |
|---|---|---|
| Linux | /proc/net/{tcp,tcp6,udp,udp6} parsed in C | /proc/<pid>/fd inode match, command from /proc/<pid>/comm |
| macOS | lsof -nP -iTCP -sTCP:LISTEN / -iUDP, falling back to netstat -an | from the lsof PID column |
| Windows | GetExtendedTcpTable(TCP_TABLE_OWNER_PID_LISTENER) + GetExtendedUdpTable | owning PID from the table, image name via QueryFullProcessImageName |
?action=probe&port=<1..65535> opens exactly one TCP connection, to
`127.0.0.1`. The destination is a static const unsigned char in the source
and is never read from a query parameter, header or environment variable, so the
plugin cannot be pointed at another host. That matters: a port scanner that can
be aimed anywhere is an SSRF pivot, and this one cannot be.
It reports:
open - did the connect succeed (2 s non-blocking timeout)connect_ms - how long the connect tookhttp_tried / http_ok / http_status / http_ms - a bounded HEAD / overthe same socket, if the connect succeeded, so an HTTP service reports its
status code and a non-HTTP service simply reports no response
./plugin_ports --meta
# {"name":"ports","desc":"Listening TCP"}
SX_PLUGIN_META=1 does the same. --meta is unauthenticated on purpose so
/plugins discovery keeps working.
QUERY_STRING='action=listeners' ./plugin_ports
QUERY_STRING='action=probe&port=8150' ./plugin_ports
QUERY_STRING='format=json' ./plugin_ports
action=listeners:
{
"ok": true,
"action": "listeners",
"source": "procfs",
"count": 3,
"summary": {"tcp": 2, "udp": 1, "loopback": 1, "wildcard": 2, "specific": 0},
"listeners": [
{"proto": "tcp", "bind_addr": "0.0.0.0", "port": 22, "scope": "wildcard", "pid": 24, "comm": "sshd"},
{"proto": "tcp", "bind_addr": "127.0.0.1", "port": 8150, "scope": "loopback", "pid": 812, "comm": "scorpiox-server"},
{"proto": "udp", "bind_addr": "127.0.0.1", "port": 5353, "scope": "loopback", "pid": 77, "comm": "mdns"}
]
}
scope is loopback (127.0.0.0/8, ::1), wildcard (0.0.0.0, ::) or
specific (any other bound address). source is procfs, lsof or
windows-tables depending on platform.
action=probe&port=N:
{
"ok": true,
"action": "probe",
"target": "127.0.0.1",
"port": 8150,
"open": true,
"refused": false,
"connect_ms": 0,
"http_tried": true,
"http_ok": true,
"http_status": 200,
"http_ms": 4,
"checked_at": "2026-11-11T05:39:50Z"
}
Errors are always JSON with "ok": false and a human error string. A port
outside 1..65535, or a missing/non-numeric port, is rejected before any socket
is opened.
A plain GET serves a responsive dark/light inspector at the node route
(/plugin_ports) and through the Bot hub (/plugins?plugin=plugin_ports). It
shows KPI counts, a filterable table (free-text across port/process/address,
plus scope and protocol filters), a Probe 127.0.0.1 button on every row, and a
standalone probe box. ?embed=1 drops the back link for the chat floating
window.
When BOT_PASSWORD is set in the node environment, every mode except --meta
requires it via X-Bot-Password: <pwd>, Authorization: Bearer <pwd> or
?pwd=<pwd>. Without it a request gets Status: 401 Unauthorized and no data.
If BOT_PASSWORD is unset the plugin is a no-op (local operator use only).
make # native glibc build -> ./plugin_ports
make musl # static x86_64 build -> ./plugin_ports.musl
make arm64 # static aarch64 build -> ./plugin_ports.arm64
make win64 # static Windows PE -> ./plugin_ports.exe
make macos # Apple clang (on macOS) -> ./plugin_ports
make test # build + tests/run.sh
Windows uses -liphlpapi -lws2_32. macOS needs _DARWIN_C_SOURCE under
-std=c99; the source defines it on __APPLE__.
make musl && install -m 0755 plugin_ports.musl ~/.scorpiox/plugins/plugin_ports
or, on BotCloud containers, /workspace/.scorpiox/plugins/. No restart: the
node resolves plugin_* routes on every request.
Prebuilts for every platform are published at
https://dist.scorpiox.net/bot-plugins/ports/, and the Bot marketplace can
install them one click or compile this source on the node itself.
tests/run.sh runs 60+ offline assertions with no network access:
TCP listener and a temporary bound UDP socket it opens itself
ss, netstat and lsof removed from PATH127.x/::1 vs 0.0.0.0/:: vs specific)against a closed port (refused, no HTTP attempt)
0, 70000, missing, non-numeric)host= and addr= parameters are ignored, and the sourcenever reads one
--meta staying open?embed=1, and no Content-Length anywheregit log -p --all audit for LAN addresses, PATs, tokens and fleet pathstests/e2e.py adds Playwright viewport checks at 1440 / 1024 / 390 and skips
cleanly when Playwright is absent.
DIST_HOST=<ssh-target> DIST_PASS=<pw> MAC_HOST=<mac> MAC_USER=<user> MAC_PASS=<pw> ./release-dist.sh
The script runs a full-history secret scan first and refuses to publish on any
hit, builds every target, writes manifest.json + SHA256SUMS + source.tar.gz,
uploads to dist.scorpiox.net/bot-plugins/ports/1.0.0/, refreshes latest.json
and the aggregate index.json, and mirrors the repository to plugingit.
{
"capabilities": ["procfs_read", "local_socket_list", "loopback_probe"],
"trust_notice": "Executes native C code on your node. Reads local kernel socket tables and /proc, and opens exactly one TCP connection to 127.0.0.1 when you ask it to probe a port. Never connects to a remote host and makes zero outbound network requests on its own."
}
It reads only local kernel structures and /proc. The single socket it ever
opens goes to loopback. It never writes a file, never changes a socket and never
touches another machine.
MIT - see LICENSE. Copyright (c) 2026 SCORPIOX INC.