mmdfathian/port-scanner

GitHub: mmdfathian/port-scanner

一个基于Python的快速端口扫描工具,用于检测网络主机的开放端口和服务,支持并行扫描和多种输出格式。

Stars: 1 | Forks: 0

# 🔍 端口扫描器 ![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/696e31be38115200.svg) ![Python](https://img.shields.io/badge/python-3.11%2B-blue) ![License](https://img.shields.io/badge/license-MIT-green) ## ✨ 功能 - 使用 ThreadPoolExecutor 进行并行扫描 (速度极快) - 使用 `rich` 库实现彩色美观输出 - 显示每个端口的服务名称 (http、ssh、ftp 等) - 支持域名和 IP 地址 - 包含运行时间和性能 (端口/秒) 的表格报告 - 提供 JSON 输出,便于其他工具集成 - 支持将报告保存到文件 - 提供完整的命令行界面 - 端口范围验证 (1-65535) - 为不稳定连接提供重试逻辑 ## 📦 安装 ``` git clone https://github.com/mmdfathian/port-scanner.git cd port-scanner pip install -e . ``` ## 🚀 使用 ``` # 默认扫描(端口 1 到 1024) port-scanner google.com # 自定义范围 port-scanner 192.168.1.1 -s 1 -e 500 # 带自定义 timeout 和 thread port-scanner example.com -s 1 -e 65535 -t 0.5 -w 200 # JSON 输出 port-scanner google.com --output json # 将 JSON 输出保存到文件 port-scanner google.com --output json --save result.json ``` ### 参数 | 参数 | 默认值 | 描述 | |--------|---------|-------| | `host` | - | 目标 IP 地址或域名 | | `-s, --start` | 1 | 端口范围起始 | | `-e, --end` | 1024 | 端口范围结束 | | `-t, --timeout` | 1.0 | 每个连接的超时时间 (秒) | | `-w, --workers` | 100 | 并行线程数 | | `-o, --output` | text | 输出格式: `text` 或 `json` | | `--save` | - | 将 JSON 输出保存到文件 | ### JSON 输出示例 ``` { "host": "google.com", "ip": "142.250.185.46", "range": { "start": 1, "end": 1024 }, "duration_seconds": 3.21, "open_ports_count": 2, "open_ports": [ { "port": 80, "service": "http" }, { "port": 443, "service": "https" } ] } ``` ## 🧪 运行测试 ``` pip install -e ".[dev]" pytest ``` ## 🗂️ 项目结构 ``` port-scanner/ ├── port_scanner/ │ ├── __init__.py │ ├── scanner.py # منطق اسکن پورت │ ├── resolver.py # تبدیل دامنه به IP │ ├── reporter.py # نمایش رنگی گزارش با rich │ └── cli.py # رابط command line ├── tests/ │ ├── test_scanner.py │ └── test_resolver.py ├── .github/workflows/ │ ├── ci.yml # اجرای خودکار تست │ └── publish.yml # انتشار روی PyPI └── pyproject.toml ``` ## ⚠️ 法律警告 请**仅在您有权扫描的系统上**使用此工具。 未经授权扫描他人的网络可能违法。 ## 📄 许可证 MIT License
标签:API安全, DNS查询工具, JSON输出, 云存储安全, 多线程扫描, 工具开发, 并发扫描, 开放端口, 性能统计, 插件系统, 文档结构分析, 服务检测, 端口扫描器, 网络安全, 网络扫描, 网络服务识别, 逆向工具, 重试逻辑, 隐私保护