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

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

相关推荐
Light601 天前
领码方案|Windows 下 PLT → PDF 转换服务超级完整版:异步、权限、进度
windows·ghostscript.net·权限治理·异步转换·进度推送·redis 存储·kubernetes 部署
染指11101 天前
11.ImGui-加载字体和中文
c++·windows·imgui
李游Leo1 天前
Rust 开发环境安装与 crates.io 国内源配置(Windows / macOS / Linux 全流程)
windows·macos·rust
小王不爱笑1321 天前
Java基础知识(十四)
java·windows·python
sc_yhsheng1 天前
18j621-3通风天窗图集pdf(免费高清版)
windows·pdf
程序员TNT1 天前
Shoptnt 促销计算引擎详解:策略模式与责任链的完美融合
linux·windows·策略模式
※※冰馨※※1 天前
【c#】 使用winform如何将一个船的图标(ship.png)添加到资源文件
开发语言·windows·c#
稻草人不怕疼1 天前
氢桌面:高德悬浮地图在滑动桌面时消失浅析
windows
iReachers1 天前
.NET 单文件程序详解:从原理到实践
windows·microsoft·.net
默默无名的大学生2 天前
数据结构—顺序表
数据结构·windows