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

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

相关推荐
技术不好的崎鸣同学8 小时前
第一章:PEB结构解析与内存定位
windows·安全·系统安全
江湖人称菠萝包12 小时前
【Windows】《深入浅出Windows API程序设计:编程基础篇》笔记-Chapter1-基础知识
windows·笔记
白山编程大哥12 小时前
Java 迭代器接口详解:从 Iterator 到 ListIterator 的完整指南
java·开发语言·windows
一叶龙洲13 小时前
Ubuntu从图标到卸载应用
linux·windows·ubuntu
江湖人称菠萝包13 小时前
【Windows】《深入浅出Windows API程序设计:编程基础篇》笔记-Chapter2-Windows窗口程序
windows·笔记
奈斯先生Vector15 小时前
AIGC 视频生成实战:用 Kling Video 拆解文生视频、图生视频与完整工作流
开发语言·人工智能·windows·python·aigc·音视频
暖焰核心15 小时前
迭代器与模板的结合——stl的list
c++·windows·list
2401_8616786215 小时前
Git 在 Windows 使用
windows·git·elasticsearch
en.en..18 小时前
LVGL 普通函数指针与结构体函数指针原理
linux·windows·microsoft
今夕资源网18 小时前
Windows 本地 HTTPS 配置教程:使用 CertTool 创建自签名证书并部署到宝塔
windows·网络协议·https