在处理ARP请求时,遇到"TypeError: handle_arp_request() missing 1 required positional argument: 'ifname'"错误,表示函数 handle_arp_request() 缺少一个名为 ifname 的参数。

错误代码示例:

if eth_type == 0x0806:
    arp_op = struct.unpack('!H', packet[ETH_HEADER_LEN+6:ETH_HEADER_LEN+8])[0]
    if arp_op == ARP_REQUEST:
        handle_arp_request(packet)  # 缺少 ifname 参数
    elif arp_op == ARP_REPLY:
        handle_arp_reply(packet)

解决方法: 在调用 handle_arp_request() 函数时需要传入 ifname 参数,例如:

if eth_type == 0x0806:
    arp_op = struct.unpack('!H', packet[ETH_HEADER_LEN+6:ETH_HEADER_LEN+8])[0]
    if arp_op == ARP_REQUEST:
        handle_arp_request(packet, ifname)  # 传入 ifname 参数
    elif arp_op == ARP_REPLY:
        handle_arp_reply(packet)

注意: ifname 应该是在调用 handle_arp_request() 之前定义的网络接口名称。

Python TypeError: handle_arp_request() missing 1 required positional argument: 'ifname' 解决方法

原文地址: https://www.cveoy.top/t/topic/jnKR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录