主机扫描—ARP

主机扫描—ARP

一、脚本介绍

1、背景介绍

最近正在学习UI所有写了一个简单的功能,所以写了这个b脚本,不喜勿喷

2、功能介绍

能通过发送ARP请求的广播报文来获取主机IP以及MAC地址

二、脚本代码

1、代码展示

# -*- coding: UTF-8 -*-
"""
# @当前项目: python
# @当前脚本: ARP_IP
# @创建者: Sword
# @时间: 2025/02/21 14:06
# @脚本说明: 
"""
from scapy.all import Ether, ARP, srp


def arp_scan(target_ip):
    # 创建以太网帧(Ether)和 ARP 请求(ARP)
    ether = Ether(dst="ff:ff:ff:ff:ff:ff")  # 广播 MAC 地址
    arp = ARP(pdst=target_ip)  # 目标 IP 地址
    packet = ether / arp  # 合成以太网帧和 ARP 请求包

    # 发送请求包并等待响应
    result = srp(packet, timeout=3, verbose=False)[0]

    # 存储设备列表
    devices = []

    for sent, received in result:
        devices.append({'ip': received.psrc, 'mac': received.hwsrc})

    # 打印结果
    return devices


def print_results(devices):
    print("IP Address\t\tMAC Address")
    print("-----------------------------------------")
    for device in devices:
        print(f"{device['ip']}\t\t{device['mac']}")


if __name__ == "__main__":
    target_ip = "192.168.1.1/24"  # 扫描整个子网,调整为你的目标网段
    devices = arp_scan(target_ip)
    print_results(devices)

2、脚本说明

请按照IP/子网掩码位数这样的格式运行

三、结果展示

1、运行结果

image-20250221162452517

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值