我正在寻找一种以编程方式(在C中)在Linux用户空间应用程序中发送免费ARP消息的方法。我注意到有一些文件用于在
的procfs中配置ARP/proc/sys/net/ipv4/conf/<interface_name>
有没有办法通过ioctl调用相应的网络接口来执行此操作?
答案 0 :(得分:3)
使用scapy:
from scapy.all import *
SELF_MAC = '02:02:02:02:02:02' # fill in with your MAC address
BCAST_MAC = 'ff:ff:ff:ff:ff:ff'
def create_ARP_request_gratuituous(ipaddr_to_broadcast):
arp = ARP(psrc=ipaddr_to_broadcast,
hwsrc=SELF_MAC,
pdst=ipaddr_to_broadcast)
return Ether(dst=BCAST_MAC) / arp
# and then call sendp() with the result