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

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

相关推荐
百事牛科技4 小时前
PPT如何添加logo?两种方法解决!
windows·powerpoint
朱一头zcy14 小时前
Win11右键菜单如何把“显示更多选项“中的内容改为默认展示出来
windows
FOREVER-Q15 小时前
Windows 下 Docker Desktop 快速入门与镜像管理
运维·服务器·windows·docker·容器
任子菲阳17 小时前
学Java第四十五天——斗地主小游戏创作
java·开发语言·windows
百事牛科技18 小时前
PDF如何设置密码?3种方法保护文件安全
windows·pdf
小龙报20 小时前
《DevC++支持C++11等与其软件分辨率低的解决办法》
c语言·c++·windows·蓝桥杯·pat考试·学习方法·dvc++
6极地诈唬1 天前
【C#-sqlSugar-sqlite】在Windows从源码编译构建System.Data.SQLite.dll的方法
windows·sqlite·c#
数据的世界011 天前
JAVA和C#的语法对比
java·windows·c#
REDcker1 天前
Cursor Chrome DevTools MCP 配置指南 for Windows
前端·windows·chrome devtools
Wins_calculator1 天前
Ubuntu重新挂载Windows C盘以及如何安全退出外挂硬盘
windows·ubuntu