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

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

相关推荐
qq_393828221 小时前
电脑休眠设置
windows·电脑·软件需求
网安小白的进阶之路4 小时前
A模块 系统与网络安全 第三门课 网络通信原理-3
网络·windows·安全·web安全·系统安全
芳草萋萋鹦鹉洲哦11 小时前
【vue3+tauri+rust】如何实现下载文件mac+windows
windows·macos·rust
李洋-蛟龙腾飞公司11 小时前
HarmonyOS NEXT应用元服务常见列表操作多类型列表项场景
windows
new_zhou15 小时前
Windows qt打包编译好的程序
开发语言·windows·qt·打包程序
Rocket MAN16 小时前
Rovo Dev CLI Windows 安装与使用指南
windows
fzyz12319 小时前
Windows系统下WSL从C盘迁移方案
人工智能·windows·深度学习·wsl
csdn_aspnet21 小时前
在 Windows 机器上安装和配置 RabbitMQ
windows·rabbitmq
csdn_aspnet1 天前
Windows Server 上的 RabbitMQ 安装和配置
windows·rabbitmq
热爱生活的猴子1 天前
Poetry 在 Linux 和 Windows 系统中的安装步骤
linux·运维·windows