这是我的脚本,看看亚马逊破折号按钮是否被按下:
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()
但是我收到以下错误消息:
Traceback (most recent call last):
File "short.py", line 12, in <module>
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
有人知道如何修复它并让它在python3.4下工作吗?
答案 0 :(得分:0)
看起来错误在于它无法在数据包中找到DHCP层。您可以在if pkt.haslayer(DHCP):
之上添加options = pkt[DHCP].options
,如下所示:
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
这样它会在查找pkt [DHCP] .options。