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

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

相关推荐
2601_9623649711 小时前
Windows Hello VS 传统密码:身份认证安全层级全面对比分析
windows·安全·电脑
Imagine Miracle16 小时前
【WSL】让WSL2后台持久运行不自动关闭的解决方案
linux·windows·wsl
啦啦啦~~~22216 小时前
经典小游X,免费刺激,可离线使用!
windows·游戏·开源软件
月走乂山18 小时前
Windows提示调制解调器报错、同交换机其他电脑正常、远程能连但浏览器打不开——本机DNS配置问题排查
windows·dns·故障排查·网络故障·网络诊断
衔烛之龙120 小时前
Windows x64 构建 liboqs-java教程
java·windows·python
阿豪只会阿巴1 天前
两小时快速入门 FastAPI--第二回
windows·python·fastapi
印度神油92 天前
Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
windows·python·ci/cd
2601_963771372 天前
Hardening Enterprise WordPress Sites Against REST API Leaks and Bad Headers
前端·windows·word·php
不要小看我们之间的羁绊啊2 天前
【windows】cc + cc switch + headroom
windows
找死的豆腐2 天前
基于.NET的Windows窗体编程之WinForms图像控件
windows·.net