zAstrvl/port-scanner
GitHub: zAstrvl/port-scanner
一个基于 Python 标准库从零编写的多线程 TCP 端口扫描器,支持服务识别、Banner 抓取和结果导出,零依赖开箱即用。
Stars: 0 | Forks: 0
# 🔍 端口扫描器
**快速且轻量级的端口扫描器,使用 Python 编写。**
开发仅用于教育目的。请仅在获得授权的系统上使用。



## 📌 关于工具
本项目是一个专为希望学习网络安全的人士开发的 **TCP 端口扫描器**。完全使用 Python 原生库从零编写;无需额外依赖。
### 功能特点
- 🚀 **多线程**扫描
- 🌐 支持 **IP 和域名**(例如:`example.com`)
- 🏷️ **服务映射**(SSH、HTTP、MySQL 等)
- 🪧 通过 **Banner grabbing** 进行版本检测
- 📊 **实时进度监控**
- 💾 使用 `-o` 标志**保存到文件**
- 🎯 灵活的端口格式:`1-1024`、`80,443,8080`、`22`
## 📁 项目
```
port-scanner/
├── scanner.py # Main Scanner
├── .gitignore
├── README.md
└── utils/
└── banner.py # ASCII banner
```
## ⚙️ 安装说明
**依赖:** Python 3.10 或更高版本
```
# Clone 代码库
git clone https://github.com/zAstrvl/port-scanner.git
cd port-scanner
# 无需额外设置,立即运行!
python scanner.py --help
```
## 🚀 使用方法
```
# 基本使用(端口范围 1-1024)
python scanner.py 192.168.1.1
# 使用域名扫描
python scanner.py example.com
# 特殊端口范围
python scanner.py 192.168.1.1 -p 1-65535
# 指定端口
python scanner.py 192.168.1.1 -p 80,443,3306,8080
# 配置线程数和超时时间
python scanner.py 192.168.1.1 -t 200 --timeout 2.0
# 将结果保存到文件
python scanner.py 192.168.1.1 -o results.txt
```
### 所有参数
| 参数 | 简写 | 默认值 | 描述 |
|-----------|----------|---------|-------------|
| `target` | — | 必填 | 目标 IP 或域名 |
| `--ports` | `-p` | `1-1024` | 端口范围或列表 |
| `--threads` | `-t` | `100` | 并发线程数 |
| `--timeout` | — | `1.0` | 连接超时时间(秒) |
| `--output` | `-o` | — | 输出文件名 |
## 📸 使用示例
```
____ _ ____
| _ \ ___ _ __| |_ / ___| ___ __ _ _ __ _ __ ___ _ __
| |_) / _ \| '__| __| \___ \ / __/ _` | '_ \| '_ \ / _ \ '__|
| __/ (_) | | | |_ ___) | (_| (_| | | | | | | | __/ |
|_| \___/|_| \__| |____/ \___\__,_|_| |_|_| |_|\___|_|
Port Scanner for Educational Purposes | Only Use on Authorized Systems
[*] example.com → 93.184.216.34 resolved.
[*] Scanning: 93.184.216.34
[*] Port range: 1 - 1024 (1024 port)
[*] Thread count: 100 | Timeout: 1.0s
[*] Start time: 2026-05-01 14:45:00
──────────────────────────────────────────────────
[*] Progress: 1024/1024 (100.0%)
══════════════════════════════════════════════════
SCAN RESULTS — 93.184.216.34
══════════════════════════════════════════════════
PORT SERVICE BANNER
──────────────────────────────────────────────────
80 http HTTP/1.1 200 OK
443 https
──────────────────────────────────────────────────
[+] Total open ports: 2
[+] Scan duration : 3.42 seconds
══════════════════════════════════════════════════
```
## 🛠️ 技术细节
- **协议:** TCP(类 SYN 连接扫描)
- **并发:** `concurrent.futures.ThreadPoolExecutor`
- **DNS 解析:** `socket.gethostbyname()`
- **Banner Grabbing:** 通过 HTTP HEAD 请求
- **依赖:** 零 —— 仅使用 Python 标准库
## ⚠️ 免责声明标签:Banner Grabbing, DNS查询工具, Python, Qt框架, TCP扫描, 开源, 插件系统, 攻击路径可视化, 无后门, 服务器安全, 服务识别, 白帽黑客, 端口扫描器, 网络安全, 轻量级工具, 逆向工具, 隐私保护, 黑客工具