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

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

相关推荐
qqww15540 分钟前
Win11更新后Edge卡顿掉帧?隐私窗口流畅解决办法
windows·edge·优化·卡顿
其实防守也摸鱼2 小时前
堆叠注入(Stacked Injection)详解
服务器·数据库·windows·https·ssl
郝学胜-神的一滴2 小时前
C++20模板元编程 05:吃透变参模板,解锁编译期万能参数能力
服务器·开发语言·c++·windows·vscode
是店小二呀4 小时前
鸿蒙PC_Dart-Sass-ohos适配全记录
linux·运维·windows
2601_9623649715 小时前
不止指纹和人脸:Windows Hello如何重塑PC生物识别安全?
windows·安全·电脑
ι:15 小时前
单相桥式全控整流仿真从零复现教学
windows·学习·matlab·simulink
YCOSA202516 小时前
BUG修复---雨晨 Windows 11 IoT 企业版 LTSC 23H2 终结版 22631.7588
windows·物联网
ayaya_mana16 小时前
Qwen3.5-9B融合DeepSeek-V4-Flash小模型实测与部署
windows·本地大模型·qwen3.5
aramae19 小时前
Python 使用库:标准库与第三方库实战
服务器·开发语言·windows·python
老王的笔记v1 天前
48期 Windows电脑护眼工具 蓝光过滤定时休息与桌面宠物提醒
windows·电脑