Shubhankgaur/python-port-scanner
GitHub: Shubhankgaur/python-port-scanner
一款基于 Python 的多线程 CLI 端口扫描器,支持 Banner 抓取和 JSON 报告导出,用于快速发现目标开放端口及识别常见服务。
Stars: 0 | Forks: 0
# Python 端口扫描器
一个基于 CLI 的多线程 Python 端口扫描器,使用 Python socket 和 threading 构建。
该扫描器能够检测开放端口、识别常见服务、执行基本的 banner grabbing,并将扫描结果导出为 JSON 格式。
## 功能特性
- 自定义目标扫描
- 自定义端口范围选择
- 使用 `ThreadPoolExecutor` 进行多线程扫描
- 支持 banner grabbing
- HTTP 服务器头信息检测
- JSON 报告导出
- 扫描耗时测量
- 使用 `argparse` 实现的简单 CLI 界面
## 使用技术
- Python 3
- socket
- threading
- concurrent.futures
- argparse
- json
## 项目结构
```
python-port-scanner/
│
├── port_scanner.py
├── README.md
└── sample_outputs/
└── sample_scan.json
```
## 使用方法
### 基础扫描
```
python port_scanner.py -t scanme.nmap.org -p 1-100
```
### 参数说明
| 参数 | 描述 |
|---|---|
| `-t` / `--target` | 目标 IP 地址或域名 |
| `-p` / `--ports` | 要扫描的端口范围 |
## 输出示例
```
PS E:\python-port-scanner> python port_scanner.py -t scanme.nmap.org -p 1-100
Port 22 is open -> SSH | SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13
Port 80 is open -> HTTP | Server: Apache/2.4.7 (Ubuntu)
Scan completed in 1.73 seconds
Scan Completed
```
## JSON 报告示例
```
[
{
"Port": 22,
"Service": "SSH",
"Banner": "SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13"
},
{
"Port": 80,
"Service": "HTTP",
"Banner": "Server: Apache/2.4.7 (Ubuntu)"
}
]
```
## 我的收获
通过这个项目我学到了:
- Python socket 编程
- 多线程扫描
- 基本的网络服务检测
- Banner grabbing 技术
- 使用 `argparse` 解析命令行参数
- JSON 报告生成
- 使用锁进行线程同步
## 免责声明
本项目仅供教育和道德测试目的创建。
请仅扫描您拥有或已获得授权测试的系统。
## 未来改进计划
- UDP 扫描
- 服务指纹识别
- 彩色终端输出
- CSV 导出支持
- 操作系统检测
- 更好的错误处理
- 进度指示器
## 作者
Shubhank Gaur
- GitHub: https://github.com/Shubhankgaur
- LinkedIn: https://linkedin.com/in/shubhank-gaur-42079a315
标签:argparse, Banner抓取, JSON导出, Python, Qt框架, ThreadPoolExecutor, 云存储安全, 套接字编程, 开源, 插件系统, 教育与学习, 数据统计, 无后门, 服务器安全, 服务识别, 端口扫描, 网络安全, 网络扫描, 隐私保护