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

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

相关推荐
jack186891 小时前
百度 AI 搜索实战:从精准获客到智能决策的应用全景
windows
道满科技2 小时前
Function Calling 参数总出错?只修参数就行
linux·windows·python
GHN19878883 小时前
开源小工具按一下空格,什么都看见了
windows
围炉聊科技5 小时前
Windows-MCP 拆解与实测:AI 操作 Windows 这件事——智能体基建系列
windows·llm·dom
面包狗AI4S6 小时前
ChatGPT/Codex Windows:本地桌面端应用离线包安装与免安装启动方法(无需管理员权限)
人工智能·windows·ai·chatgpt
自养Agent6 小时前
MCP Server Boundary Audit Report
linux·服务器·人工智能·windows·大模型·llm
2301_786756609 小时前
中科院分区表停发后,期刊评价的技术逻辑:从期刊超越指数到多指标选刊方案
java·数据库·windows
是我知白哒11 小时前
下载的图片Windows上无法设置为屏保如何解决
windows
Vex2une11 小时前
获取 PowerToys - 从系统外挂工具到开源效率平台
windows·开源·效率工具·powertoys·fancyzones·command palette·键盘管理器
骇客野人13 小时前
Windows 安全清理临时文件 bat 脚本
windows·安全