扫描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来处理,这个比方法一会快一点。

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

相关推荐
一路向北North1 小时前
windows如何部署deepseek
windows
剪刀石头布Cheers15 小时前
NDM浏览器插件无法连接后台的问题
windows·端口冲突·ndm
PiaoShiSun20 小时前
Windows环境下批量删除文件夹内仅有1个/2个/*个文件的文件夹
windows·批量删除单文件的文件夹
足球中国21 小时前
nuget把缓存搬离C盘
c语言·windows·缓存
love530love1 天前
ComfyUI 插件发布 GitHub Release + Comfy Registry (官方节点商店)完整复盘教程(从零开始)
人工智能·windows·github·devops
ofoxcoding1 天前
Windows 上 Codex 报 “failed to start codex app-server“:成因与修复(2026)
windows·ai
liuyukuan1 天前
C盘清理之Windows.db
windows·c盘红了
每天都进步一点点1 天前
Windows 系统安装 Python 3.11+ 详细教程
windows·python3.11
开发小程序的之朴1 天前
安企CMS的安装-PHPStudy(小皮面板)部署
windows·mysql·nginx
love530love1 天前
【硬核排障 & 猴子补丁 & 幽灵节点】SageAttention GQA 崩溃与 Flash Attention 兼容性修复全记录
ide·人工智能·windows·comfyui·sageattention·windows cuda