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

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

相关推荐
yaoxin52112314 小时前
324. Java Stream API - 实现 Collector 接口:自定义你的流式收集器
java·windows·python
非凡ghost15 小时前
小X分身APP(手机分身类工具)
android·windows·学习·智能手机·软件需求
Bruce_Liuxiaowei16 小时前
渗透测试中的提权漏洞:从低权限到系统控制的全解析
网络·windows·安全
kaizq17 小时前
Windows下基于Python构造Dify可视应用环境[非Dock]
windows·python·dify·大语言模型llm·人工智能ai·智能体agent
取个名字太难了a17 小时前
Win7 x64 内存管理(一)
windows
程序员陆通20 小时前
零基础零成本把Clawdbot(OpenClaw)在Windows电脑上部署起来
windows
盘古工具21 小时前
告别重复数据:Excel禁止重复输入的两种方法
windows·excel
x***r1511 天前
windows7安装步骤详解(附U盘启动盘制作与常见问题解决)
windows
xyzhan1 天前
RAD Studio Amalthea Delphi 13.1 Beta深度解析:Delphi重磅更新,原生支持Windows ARM64EC
windows·delphi·rad studio·c++ builder·delphi 13
YoungHong19921 天前
Windows Terminal:AI时代的现代化命令行方案
windows·terminal·powershell7