Python scapy prn 发送 rcv 错误
Python scapy prn send rcv error
我正在关注这本名为 violent python 的书,在 CH5 中,它通过编写脚本来查找 iphone wifi 端的 mac 地址。并通过将最后一个字节递增 1 来检查蓝牙是否打开。基本上找到一个 iphone 有隐藏模式的蓝牙。
我很困惑为什么脚本会这样出错。我该怎么做才能防止将来出现此错误?
下面是脚本:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from scapy.all import *
from bluetooth import *
def retBtAddr(addr):
btAddr=str(hex(int(addr.replace(':', ''), 16) + 1))[2:]
btAddr=btAddr[0:2]+":"+btAddr[2:4]+":"+btAddr[4:6]+":"+\
btAddr[6:8]+":"+btAddr[8:10]+":"+btAddr[10:12]
return btAddr
def checkBluetooth(btAddr):
btName = lookup_name(btAddr)
if btName:
print '[+] Detected Bluetooth Device: ' + btName
else:
print '[-] Failed to Detect Bluetooth Device.'
def wifiPrint(pkt):
iPhone_OUI = 'd0:23:db'
if pkt.haslayer(Dot11):
wifiMAC = pkt.getlayer(Dot11).addr2
if iPhone_OUI == wifiMAC[:8]:
print '[*] Detected iPhone MAC: ' + wifiMAC
btAddr = retBtAddr(wifiMAC)
print '[+] Testing Bluetooth MAC: ' + btAddr
checkBluetooth(btAddr)
conf.iface = 'wlan1mon'
sniff(prn=wifiPrint)
我收到错误消息:
sudo python 10-iphoneFinder.py
Traceback (most recent call last):
File "10-iphoneFinder.py", line 34, in <module>
sniff(prn=wifiPrint)
File "/home/rb/.local/lib/python2.7/site-packages/scapy/sendrecv.py", line 620, in sniff
r = prn(p)
File "10-iphoneFinder.py", line 26, in wifiPrint
if iPhone_OUI == wifiMAC[:8]:
TypeError: 'NoneType' object has no attribute '__getitem__'
在Scapy中,Dot11
层中的addr2
字段是一个条件字段,因此当嗅探到的数据包没有该字段时,它的值可能为None
。
下面是我们如何编写 wifiPrint()
函数:
IPHONE_OUI = 'd0:23:db:'
def wifiPrint(pkt):
if Dot11 in pkt:
wifiMAC = pkt[Dot11].addr2
if wifiMAC is not None and wifiMAC.startswith(IPHONE_OUI):
print '[*] Detected iPhone MAC: ' + wifiMAC
btAddr = retBtAddr(wifiMAC)
print '[+] Testing Bluetooth MAC: ' + btAddr
checkBluetooth(btAddr)
附带说明一下,至少可以说,脚本的编码不是很好。从中学习Scapy(甚至Python)可能不是一个好主意。
我正在关注这本名为 violent python 的书,在 CH5 中,它通过编写脚本来查找 iphone wifi 端的 mac 地址。并通过将最后一个字节递增 1 来检查蓝牙是否打开。基本上找到一个 iphone 有隐藏模式的蓝牙。
我很困惑为什么脚本会这样出错。我该怎么做才能防止将来出现此错误?
下面是脚本:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from scapy.all import *
from bluetooth import *
def retBtAddr(addr):
btAddr=str(hex(int(addr.replace(':', ''), 16) + 1))[2:]
btAddr=btAddr[0:2]+":"+btAddr[2:4]+":"+btAddr[4:6]+":"+\
btAddr[6:8]+":"+btAddr[8:10]+":"+btAddr[10:12]
return btAddr
def checkBluetooth(btAddr):
btName = lookup_name(btAddr)
if btName:
print '[+] Detected Bluetooth Device: ' + btName
else:
print '[-] Failed to Detect Bluetooth Device.'
def wifiPrint(pkt):
iPhone_OUI = 'd0:23:db'
if pkt.haslayer(Dot11):
wifiMAC = pkt.getlayer(Dot11).addr2
if iPhone_OUI == wifiMAC[:8]:
print '[*] Detected iPhone MAC: ' + wifiMAC
btAddr = retBtAddr(wifiMAC)
print '[+] Testing Bluetooth MAC: ' + btAddr
checkBluetooth(btAddr)
conf.iface = 'wlan1mon'
sniff(prn=wifiPrint)
我收到错误消息:
sudo python 10-iphoneFinder.py
Traceback (most recent call last):
File "10-iphoneFinder.py", line 34, in <module>
sniff(prn=wifiPrint)
File "/home/rb/.local/lib/python2.7/site-packages/scapy/sendrecv.py", line 620, in sniff
r = prn(p)
File "10-iphoneFinder.py", line 26, in wifiPrint
if iPhone_OUI == wifiMAC[:8]:
TypeError: 'NoneType' object has no attribute '__getitem__'
在Scapy中,Dot11
层中的addr2
字段是一个条件字段,因此当嗅探到的数据包没有该字段时,它的值可能为None
。
下面是我们如何编写 wifiPrint()
函数:
IPHONE_OUI = 'd0:23:db:'
def wifiPrint(pkt):
if Dot11 in pkt:
wifiMAC = pkt[Dot11].addr2
if wifiMAC is not None and wifiMAC.startswith(IPHONE_OUI):
print '[*] Detected iPhone MAC: ' + wifiMAC
btAddr = retBtAddr(wifiMAC)
print '[+] Testing Bluetooth MAC: ' + btAddr
checkBluetooth(btAddr)
附带说明一下,至少可以说,脚本的编码不是很好。从中学习Scapy(甚至Python)可能不是一个好主意。