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.

67 lines
1.8 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)))
  20. dev.ssl = True
  21. dev.ssl_certificate = client_cert
  22. dev.ssl_key = client_key
  23. dev.ssl_ca = ca_cert
  24. dev.open(no_reader_thread=True)
  25. dev.write("\r") # HACK: Prime the pump. This likely has to do with the SSL handshake
  26. # not being completed when we get down to the select.
  27. while running:
  28. ifh, ofh, efh = select.select([sys.stdin, dev._device], [], [], 0)
  29. for h in ifh:
  30. if h == sys.stdin:
  31. data = h.read(1)
  32. # Break out if we get a CTRL-C
  33. if data == "\x03":
  34. print "Exiting..\r"
  35. running = False
  36. break
  37. else:
  38. dev.write(data)
  39. else:
  40. data = h.read(100)
  41. sys.stdout.write(data)
  42. sys.stdout.flush()
  43. dev.close()
  44. print "Connection closed.\r"
  45. finally:
  46. termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, old_term_settings)
  47. if __name__ == '__main__':
  48. main()