#! /usr/bin/python import binascii import struct import sys, os, time import bluepy.btle as btle deviceMAC = open('ctf_mac.txt').read() p = btle.Peripheral(deviceMAC) print ("Attached to peripheral") services=p.getServices() for service in services: print (service) q = service.getCharacteristics() for characteristic in q: hex1 = int(format(characteristic.getHandle(),'02X'), 16) if (characteristic.supportsRead()): hex2 = binascii.b2a_hex(p.readCharacteristic(hex1)) hexlif2 = binascii.unhexlify(hex2) print (str(hex1)+" 0x"+ format(characteristic.getHandle(),'02X') +" "+ characteristic.propertiesToString() + " " + hexlif2) else: print (str(hex1)+" 0x"+ format(characteristic.getHandle(),'02X') +" "+ characteristic.propertiesToString() ) p.disconnect()