diff options
Diffstat (limited to 'dcs8000lh-configure.py')
-rwxr-xr-x | dcs8000lh-configure.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/dcs8000lh-configure.py b/dcs8000lh-configure.py index 35fa476..fa057ec 100755 --- a/dcs8000lh-configure.py +++ b/dcs8000lh-configure.py @@ -1,26 +1,25 @@ #!/usr/bin/python3 import sys +import hashlib +import base64 from bluepy.btle import Peripheral class BleCam(object): - def __init__(self, address): - try: - self.periph = Peripheral(address) - except BTLEDisconnectError: - print("failed to connect to <addr>".format(address)) - return + def __init__(self, address, pincode): + self.pincode = pincode + self.periph = Peripheral(address) self.ipcamservice() self.dumpchars() self.experiment() def ipcamservice(self): try: - print("getting service") + print("getting IPCam service") self.service = self.periph.getServiceByUUID(0xD001) except BTLEEException: - print("no such service") - return + print("no IPCam service found for %s" % periph.address) + def dumpchars(self): handles = self.service.getCharacteristics() @@ -29,12 +28,27 @@ class BleCam(object): print("%s - Properties=%s Handle=%#06x " % (h.uuid, h.propertiesToString(), h.getHandle())) def experiment(self): - print("read %s" % self.service.getCharacteristics(0xa001)[0].read().decode()) - + auth = self.service.getCharacteristics(0xa001)[0] + tmp = auth.read().decode().split(";", 10) + for t in tmp: + if t.startswith("C="): + self.challenge=t.split("=",2)[1] + print("challenge is %s" % self.challenge) + name = "DCS-8000LH-CC73" + hashit = name + self.pincode + self.challenge + self.key = base64.b64encode(hashlib.md5(hashit.encode()).digest())[:16] + print ("key is %s" % self.key) + try: + auth.write("M=0;K=".encode() + self.key, True) + except: + print("write failed") + print("ip config is %s" % self.service.getCharacteristics(0xa104)[0].read()) + + if __name__ == '__main__': - if len(sys.argv) < 2: - print("Usage: {} <addr>".format(sys.argv[0])) + if len(sys.argv) < 3: + print("Usage: {} <addr> <pincode>".format(sys.argv[0])) sys.exit(1) - BleCam(sys.argv[1]) + BleCam(sys.argv[1], sys.argv[2]) print("Done.") |