npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stdafx/portscan

v1.0.1

Published

Scan a CIDR range for hosts with a specific TCP port open

Readme

portscan

扫描 CIDR 网段内所有开放指定 TCP 端口的主机。零运行时依赖,支持 CLI 和浏览器两种使用方式。

安装

# 全局安装
npm install -g @stdafx/portscan

# 或无需安装,直接使用 npx
npx @stdafx/portscan <cidr> <port>

CLI 用法

portscan <cidr> <port> [选项]

示例

# 扫描 192.168.0.0/24 网段内所有开放 12345 端口的主机
portscan 192.168.0.0/24 12345

# 自定义超时与并发数
portscan 192.168.1.0/24 22 --timeout 500 --concurrency 50

# 结果通过管道传给其他命令
portscan 10.0.0.0/24 80 | xargs -I{} curl -s http://{}

参数

| 参数 | 说明 | |---|---| | <cidr> | IPv4 CIDR 网段,如 192.168.0.0/24 | | <port> | 要探测的 TCP 端口(1–65535) |

选项

| 选项 | 默认值 | 说明 | |---|---|---| | --timeout <ms> | 1000 | 每台主机的连接超时(毫秒) | | --concurrency <n> | 100 | 并发探测数量 | | --help | — | 显示帮助信息 |

输出说明

  • stdout:每行一个开放主机的 IP,方便管道传递
  • stderr:扫描进度和完成摘要
Scanning 254 hosts on port 22...
[50/254]
10.8.0.12
10.8.0.34
[254/254]
Done. Found 2 open host(s) in 3.1s

浏览器页面

直接在浏览器中打开 portscan.html(Chrome、Firefox、Edge 均支持):

# macOS
open portscan.html

# Linux
xdg-open portscan.html

# Windows
start portscan.html

在页面中输入 CIDR 网段和端口,点击 Scan,结果实时滚动显示。

注意:浏览器页面使用 fetch 探测(非原生 TCP),通过判断主机是否在超时前响应来推断端口是否开放。 请通过 file://http:// 打开页面,不支持在 https:// 页面中使用

工作原理

CLI:使用 Node.js net.createConnection 发起真实 TCP 握手,连接成功即视为端口开放。通过并发池控制同时探测数量,结果实时输出,无需等待全部完成。

浏览器:使用 fetch + AbortController 探测每台主机。快速返回错误(CORS 错误、连接拒绝)表示端口有响应;超时则视为关闭/被过滤。

发布到 npm

前置条件

  1. 注册 npmjs.com 账号
  2. 在终端登录:
npm login
# 按提示输入用户名、密码和邮箱(或使用一次性密码)

发布步骤

# 1. 确认当前登录账号
npm whoami

# 2. 预览将要打包的文件(确认无敏感文件)
npm pack --dry-run

# 3. 正式发布
npm publish

# 若包名已被占用,可加 scope 发布为私有/组织包:
# npm publish --access public

发布后使用

npx @stdafx/portscan 192.168.0.0/24 12345

更新版本

# 修补版本 1.0.0 → 1.0.1
npm version patch

# 次要版本 1.0.0 → 1.1.0
npm version minor

# 主版本 1.0.0 → 2.0.0
npm version major

# 然后发布
npm publish

环境要求

  • Node.js ≥ 18
  • 对目标网络拥有合法的扫描授权

License

MIT