简体   繁体   English

Python中不安全的rfcomm连接

[英]Insecure rfcomm connection in Python

I would like to establish a bluetooth connection from an android device to a Raspberry Pi without pairing. 我想建立一个从android设备到Raspberry Pi的蓝牙连接而无需配对。 The language used in RPi is Python. RPi中使用的语言是Python。 I am connecting using createInsecureRfcommSocketToServiceRecord from android. 我正在使用来自android的createInsecureRfcommSocketToServiceRecord连接。

However the connection is established only when the two devices are paired. 但是,仅当两个设备配对时才建立连接。 Is there an equivalent of listenUsingInsecureRfcommWithServiceRecord in Python? Python中是否有等效的listenUsingInsecureRfcommWithServiceRecord

Raspberry Pi code 树莓派代码

server_sock=BluetoothSocket( RFCOMM )
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)
port = server_sock.getsockname()[1]

uuid = "f3c74f47-1d38-49ed-8bbc-0369b3eb277c"

advertise_service( server_sock, "AquaPiServer",
                   service_id = uuid,
                   service_classes = [ uuid, SERIAL_PORT_CLASS ],
                   profiles = [ SERIAL_PORT_PROFILE ], 
                   )

    client_sock, client_info = server_sock.accept()
    print "Accepted connection from ", client_info

Android code Android代码

BluetoothDevice device = blueAdapter.getRemoteDevice(RPi_MAC);
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString("f3c74f47-1d38-49ed-8bbc-0369b3eb277c"));
blueAdapter.cancelDiscovery();
socket.connect();

I was able to connect to the Raspberry Pi without pairing. 我无需配对即可连接到Raspberry Pi。 For this I had to make the RPi discoverable. 为此,我必须使RPi易于发现。 Then I used socket.connect() from my Nexus running on Marshmallow. 然后,我使用了在棉花糖上运行的Nexus上的socket.connect() By doing this I was able to get the MAC address of my Nexus in the RPi. 这样,我就可以在RPi中获得Nexus的MAC地址。 Only problem is that I get a pairing request every time I connect but the MAC address was what I wanted. 唯一的问题是每次连接时都会收到一个配对请求,但MAC地址正是我想要的。

Thanks for your inputs David! 感谢您的输入,大卫!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 客户端 GRPC 与 AWS 的不安全连接问题 - Python client GRPC insecure connection problem with AWS Python Selenium Firefox-不安全的连接错误警报 - Python Selenium Firefox - Insecure Connection Error Alert 简单的 HTTPS python 服务器连接到 ca-cert 连接而不是不安全的连接 - Simple HTTPS python server to connect to ca-cert connection and not to insecure connection Python 替代 linux 蓝牙命令“rfcomm connect” - Python alternative to linux bluetooth command “rfcomm connect” 通过 python 以编程方式将蓝牙设备绑定到 rfcomm - Bind Bluetooth device programmatically to rfcomm via python in 这个Python登录几乎不安全吗? - Is this Python login practically insecure? 如何在从 python selenium 脚本打开私人浏览器时禁用“不安全连接”? - How to disable the "Insecure Connection" while opening up a private browser from python selenium script? 互联网上的 Python “多处理”服务器是否不安全? - Are Python "multiprocessing" servers on the Internet insecure? 无法运行python-bluez RFCOMM服务器示例脚本 - Cannot run python-bluez RFCOMM server example script 使用python 3中的套接字库(RFCOMM模式)重新连接蓝牙设备? - Reconnecting a Bluetooth device using socket library (RFCOMM mode) in python 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM