Tenebris404/Port-Scanner

GitHub: Tenebris404/Port-Scanner

一个基于 Python 多线程的零依赖 TCP 端口扫描器,可快速探测目标主机指定范围内的开放端口。

Stars: 0 | Forks: 0

# 🚀 Port Scanner [![Python](https://img.shields.io/badge/Python-3.7%2B-blue?logo=python&logoColor=white)](https://python.org) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Stars](https://img.shields.io/github/stars/Tenebris404/Port-scanner?style=social)](https://github.com/Tenebris404/Port-scanner/stargazers) ## ✨ 功能 | 功能 | 描述 | |---------|-------------| | ⚡ **多线程** | 并发扫描端口以实现最高速度 | | 🎯 **自定义范围** | 扫描任意端口范围 (1-65535) | | 🌐 **主机名支持** | 自动解析域名 | | ⏱️ **超时处理** | 1 秒超时防止挂起 | | 📊 **简洁输出** | 仅显示开放端口 — 拒绝冗余信息 | | 🐍 **零依赖** | 纯 Python 标准库 | ## 📦 安装说明 ``` git clone https://github.com/Tenebris404/Port-scanner.git cd Port-scanner ``` 无需 `pip install` — 可在任何 Python 3.7+ 环境下运行! ## 🚀 快速开始 ``` # 扫描目标的 1-1000 端口 python port_scanner.py example.com 1 1000 # 扫描 localhost 的常见端口 python port_scanner.py 127.0.0.1 1 1024 # 扫描特定服务范围 python port_scanner.py 192.168.1.1 80 443 ``` **参数:** | 参数 | 描述 | 示例 | |----------|-------------|---------| | `TARGET` | IP 地址或主机名 | `google.com`, `192.168.1.1` | | `START_PORT` | 首个扫描端口 | `1`, `80`, `1000` | | `END_PORT` | 最后一个扫描端口 | `1000`, `65535` | ## 📸 演示 ``` $ python port_scanner.py scanme.nmap.org 1 1000 -- Port Scanner -- python simple port scanner that scans a range of ports on a target host Scanning target 45.33.32.156 from port 1 to 1000 Port 22 is open Port 80 is open Scanning completed in 2.34 seconds ``` ## ⚙️ 工作原理 ``` # 核心扫描逻辑(简化版) def scan_port(port): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) result = sock.connect_ex((target, port)) if result == 0: print(f"Port {port} is open") sock.close() # Threaded 执行以提升速度 for port in range(start_port, end_port + 1): threading.Thread(target=scan_port, args=(port,)).start() time.sleep(0.01) # Rate limiting ``` - **`connect_ex()`** — 成功时返回 `0`(端口开放),否则返回错误代码 - **多线程** — 每个端口分配独立的线程进行并行扫描 - **超时** — 1 秒超时防止在被过滤的端口上挂起 - **速率限制** — 线程生成之间的 10 毫秒延迟可防止目标过载 ## 🛡️ 合法与道德使用 未经授权的端口扫描可能违反: - 计算机欺诈和滥用法案 (CFAA) — 美国 - 滥用计算机法案 — 英国 - 其他司法管辖区的类似法律 **授权的使用场景:** - ✅ 网络管理与资产盘点 - ✅ 安全审计(需获得书面授权) - ✅ CTF 挑战与学习环境 - ✅ 个人网络故障排除 ## 📄 许可证 基于 MIT 许可证发布。查看 `LICENSE` 获取更多信息。 ## 📬 联系方式 **Tenebris404** — [@Tenebris404](https://github.com/Tenebris404) 项目链接:[https://github.com/Tenebris404/Port-scanner](https://github.com/Tenebris404/Port-scanner)
用 ☕ 和 🐍 构建 | 专为教育目的而制作
标签:Python, 插件系统, 数据统计, 无后门, 端口扫描, 网络安全, 逆向工具, 隐私保护