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

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

相关推荐
好好沉淀10 分钟前
Windows 下升级 Maven 3.6.1 到 3.9.9 踩坑全记录
java·windows·maven
weixin_4365250726 分钟前
Windows 上终止占用的端口进程
windows
古道青阳43 分钟前
Duilib 技术全景剖析
c++·windows
jing.wang_20252 小时前
NVIDIA CUDA C++编程环境搭建--Windows + Ubuntu 22.04
c++·windows·ubuntu·gpu算力
wechatbot8882 小时前
解决企业微信官方 API 短板:iPad 协议全功能对接方案
java·汇编·windows·http·微信·企业微信
测试专家2 小时前
PCI-1553B板卡在 Windows Server 2016 服务器安装流程详解
服务器·windows·单片机
西邮彭于晏2 小时前
Conda 常用命令速查手册:从入门到精通
windows·conda
米尔的可达鸭2 小时前
UDP 通信深度实验:从 Windows FastPath 到 ICMP 端口不可达的完整排查
windows·websocket·网络协议·rust·udp·wireshark·tcpdump
WangWei_CM3 小时前
Windows 进程枚举的 Native API 缓冲区遍历
windows
王维同学15 小时前
Winsock 协议与名称空间 Provider 目录
网络·c++·windows·安全