from bluetooth import *; sock = BluetoothSocket( RFCOMM ); sock.bind( ('', PORT_ANY) ); sock.listen(1); port = sock.getsockname()[1];