扫描IP段内的使用的IP

扫描IP段内的使用的IP

方法一:命令行

命令行进入

bash 复制代码
for /L %i IN (1,1,254) DO ping -w 1 -n 1 192.168.3.%i
bash 复制代码
arp -a

方法二:python

python 复制代码
from scapy.all import ARP, Ether, srp
import keyboard


def scan_network(ip_range):
    # 创建一个ARP请求包
    arp = ARP(pdst=ip_range)
    ether = Ether(dst="ff:ff:ff:ff:ff:ff")
    packet = ether / arp

    # 发送包并接收响应
    result = srp(packet, timeout=2, verbose=0)[0]

    # 解析响应
    devices = []
    for sent, received in result:
        devices.append({'ip': received.psrc, 'mac': received.hwsrc})

    return devices


if __name__ == "__main__":
    # 指定要扫描的网段
    target_ip_range = str(input("请输入IP(格式:192.168.20.0/23):"))
    # target_ip_range = "192.168.20.0/23"
    active_devices = scan_network(target_ip_range)
    print("Active devices in the network:")
    for device in active_devices:
        print(f"IP: {device['ip']}, MAC: {device['mac']}")
    print("按空格键退出")
    # 检查是否有按键被按下
    while True:
        if keyboard.is_pressed('space'):
            print("Exiting...")
            break

可以用pyinstaller打包成exe来处理,这个比方法一会快一点。

还有优化空间,因为目前是单线程来的

相关推荐
Python私教23 分钟前
HermesAgent 终端工具 Windows 兼容性修复实战:两个 Bug 的排查与解决
windows·bug
spencer_tseng1 小时前
redis.windows.conf 2026.04.27
windows·redis
半拉老头4 小时前
修复u盘提示格式化一例
windows
IOT那些事儿4 小时前
Windows PowerShell配置Qt5编译运行环境
windows·powershell·qt5
醇氧5 小时前
WSL2(Windows Subsystem for Linux ) 从入门到实践指南
linux·运维·服务器·windows·学习
Python私教6 小时前
HermesAgent 在 Windows 原生环境安装运行指南
windows
H Journey6 小时前
Windows + VSCode + CMake 编译
windows·vscode·cmake
KivenMitnick6 小时前
CialloVOL 1.2:便捷好用的轻量化内存取证分析平台
windows·python·安全·网络安全·flask·系统安全·安全威胁分析
阿昭L7 小时前
使用内核对象进行线程同步
windows·线程同步
张赐荣7 小时前
深入详解在 Python 中用 ctypes 调用 Windows API 清空回收站
开发语言·windows·python