python dash button trigger not working
<p>this is my script to see if the amazon dash button is pressed:</p>

<pre><code>from scapy.all import *

def udp_filter(pkt):
  options = pkt[DHCP].options
  for option in options:
    if isinstance(option, tuple):
     if 'requested_addr' in option:
       print('button pressed')
       break

print('Waiting for a button press...')
sniff(prn=udp_filter, store=0, count=0, filter="udp", lfilter=lambda d: d.src == '8c:xx:xx:xx:xx:xx')

if __name__ == "__main__":
  main()
</code></pre>

<p>but i got the following error message:</p>

<pre><code>Traceback (most recent call last):
  File "short.py", line 12, in &lt;module&gt;
    sniff(prn=udp_filter, store=0, count=0, filter="udp", lfilter=lambda d: d.src == '8c:xx:xx:xx:xx:xx')
  File "/usr/local/lib/python3.4/dist-packages/scapy/sendrecv.py", line 597, in sniff
    r = prn(p)
  File "dash.py", line 4, in udp_filter
    options = pkt[DHCP].options
  File "/usr/local/lib/python3.4/dist-packages/scapy/packet.py", line 814, in __getitem__
    raise IndexError("Layer [%s] not found" % lname)
IndexError: Layer [DHCP] not found
</code></pre>

<p>has someone a idea how to fix it and get it working under python3.4?</p>

<p>It looks like the error is saying it can't find a DHCP Layer in the packet.  Could you add <code>if pkt.haslayer(DHCP):</code> just above <code>options = pkt[DHCP].options</code> like this:</p>

<p><code>def udp_filter(pkt):
    if pkt.haslayer(DHCP):
        options = pkt[DHCP].options
        for option in options:
            if isinstance(option, tuple):
            if 'requested_addr' in option:
                print('button pressed')
                break
    else: pass</code><br>
That way it will check for DHCP before looking for pkt[DHCP].options.</p>

python python-3.x