如何用Scapy发送BluetoothRFCommSocket?

问题描述 投票:0回答:1

我用这个代码设置了一个BluetoothRFCommSocket。

    from scapy.layers.bluetooth import *
    from scapy.all import *
    bt = BluetoothRFCommSocket('68:A0:3E:CC:24:06',2)

而错误是:

    Traceback (most recent call last):
      File "test.py", line 3, in <module>
        bt = BluetoothRFCommSocket('68:A0:3E:CC:24:06',2)
      File "/usr/local/lib/python2.7/dist-packages/scapy-2.4.3rc1.dev120-py2.7.egg/scapy/layers/bluetooth.py", line 1229, in __init__
        s.connect((bt_address, port))
      File "/usr/lib/python2.7/socket.py", line 228, in meth
        return getattr(self._sock,name)(*args)
    socket.error: [Errno 22] Invalid argument

正确的设置BluetoothRFCommSocket并发送的方法是什么?

python bluetooth scapy rfcomm
1个回答
0
投票

我也得到这个错误。

从scapy的源码来看。

class BluetoothRFCommSocket(BluetoothL2CAPSocket):
"""read/write packets on a connected RFCOMM socket"""

def __init__(self, bt_address, port=0):
    s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW,
                      socket.BTPROTO_RFCOMM)
    s.connect((bt_address, port))
    self.ins = self.outs = s

Scapy使用SOCK_RAW来创建套接字,但似乎RFCOMM不支持这个(我也试过使用c_types和libc,但错误还是发生了)。

将SOCK_RAW替换为SOCK_STREAM就可以消除错误,这就是PyBluez的使用方法。

(L2CAP支持SOCK_RAW)

© www.soinside.com 2019 - 2024. All rights reserved.