A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.7 KiB

  1. #!/usr/bin/env python
  2. import pyad2usb.ad2usb
  3. import sys, select
  4. import termios, tty
  5. import time
  6. def main():
  7. if len(sys.argv) != 5:
  8. print "Syntax: sslterm.py [host:port] [ca cert] [client cert] [client key]\r"
  9. return 1
  10. host, port = sys.argv[1].split(':')
  11. ca_cert = sys.argv[2]
  12. client_cert = sys.argv[3]
  13. client_key = sys.argv[4]
  14. running = True
  15. old_term_settings = termios.tcgetattr(sys.stdin.fileno())
  16. tty.setraw(sys.stdin.fileno())
  17. try:
  18. print "Opening connection to {0}:{1}\r".format(host, port)
  19. dev = pyad2usb.ad2usb.devices.SocketDevice(interface=(host, int(port)), use_ssl=True, ssl_certificate=client_cert, ssl_key=client_key, ssl_ca=ca_cert)
  20. dev.open(no_reader_thread=True)
  21. dev.write("\r") # HACK: Prime the pump. This likely has to do with the SSL handshake
  22. # not being completed when we get down to the select.
  23. while running:
  24. ifh, ofh, efh = select.select([sys.stdin, dev._device], [], [], 0)
  25. for h in ifh:
  26. if h == sys.stdin:
  27. data = h.read(1)
  28. # Break out if we get a CTRL-C
  29. if data == "\x03":
  30. print "Exiting..\r"
  31. running = False
  32. break
  33. else:
  34. dev.write(data)
  35. else:
  36. data = h.read(100)
  37. sys.stdout.write(data)
  38. sys.stdout.flush()
  39. dev.close()
  40. print "Connection closed.\r"
  41. finally:
  42. termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, old_term_settings)
  43. if __name__ == '__main__':
  44. main()