from scapy.all import Ether, IP, ICMP, sendp, Raw# 构造以太网帧eth = Ether(dst="AA:BB:CC:DD:EE:FF") # 目标MACip = IP(dst="192.168.1.100") # 目标IP(同一网段)icmp = ICMP()# 直接在二层发送#sendp(eth/ip/icmp)#不依赖 IP,纯二层包:sendp(Ether(dst="AA:BB:CC:DD:EE:FF") / Raw(load="hello"))包结构为:
以太网帧头(14字节) + 原始数据"hello"(5字节)总长度:14 + 5 = 19 字节
Wireshark 里会显示:Length:19 bytes
发送1个包:
sendp(Ether(dst="AA:BB:CC:DD:EE:FF") / Raw(load="hello"))发送100个包:
# 连续发送 100 个包sendp( Ether(dst="AA:BB:CC:DD:EE:FF") / Raw(load="hello"), count=100 # 发送100个)无限循环发送:
sendp( Ether(dst="AA:BB:CC:DD:EE:FF") / Raw(load="hello"), loop=1 # 无限发送)带间隔时间发送100个包:
sendp( Ether(dst="AA:BB:CC:DD:EE:FF") / Raw(load="hello"), count=100, inter=0.1 # 每0.1秒发1个)eth.dst == aa:bb:cc:dd:ee:ff