如何使用 Scapy 发送 BluetoothRFCommSocket?

How to send BluetoothRFCommSocket with Scapy?

我用这段代码设置了一个 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并发送的正确方法是什么?

我也遇到这个错误。

来自 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 将消除 error.This 是 PyBluez 使用的方式。

(L2CAP 支持 SOCK_RAW)