2017-09-17 10 views
1

私はこの本の中で暴力的なpythonと呼ばれています.CH5では、iPhoneの無線LAN側のMACアドレスを見つけるためのスクリプトを作成します。また、最後のバイトを1つインクリメントしてBluetoothがオンになっているかどうかを確認します。基本的に隠されたモードでブルートゥースを持っているiPhoneを見つける。Python scapy prn send rcv error

なぜ私はそのようなスクリプトのエラーアウト混乱しています。このエラーを未然に防ぐために何ができますか? iが受信

#!/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) 

エラーメッセージ:ここ

は、以下のスクリプトであるScapyで

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__' 

答えて

0

、​​層におけるaddr2フィールドが条件付きフィールドであるので、有していてもよいですスニッフィングされたパケットにそのようなフィールドがない場合の値はNoneです。控えめに言っても、スクリプトは本当によくコード化されていない側の注意点として

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) 

:ここ

たちはwifiPrint()関数を書くことができるかです。多分それからScapy(またはPython)を学ぶのは良い考えではないでしょう。