PageRenderTime 78ms CodeModel.GetById 49ms RepoModel.GetById 4ms app.codeStats 1ms

/scripts/circuits.sniff

https://bitbucket.org/prologic/circuits/
Unknown | 77 lines | 55 code | 22 blank | 0 comment | 0 complexity | 4cd9428d7eecba0f2df4b207be6cc319 MD5 | raw file
  1. #!/usr/bin/env python
  2. """(Tool) Event Sniffer
  3. Event sniffing tool. This tool can be used to sniff and debug Events as they
  4. occur in another system. As long as that system has an instnace of the Bridge
  5. Component, events can be sniffed and printed.
  6. """
  7. import optparse
  8. import circuits
  9. from circuits import Debugger, Bridge, Manager
  10. USAGE = "%prog [options] [host[:port]]"
  11. VERSION = "%prog v" + circuits.__version__
  12. ###
  13. ### Functions
  14. ###
  15. def parse_options():
  16. """parse_options() -> opts, args
  17. Parse the command-line options given returning both
  18. the parsed options and arguments.
  19. """
  20. parser = optparse.OptionParser(usage=USAGE, version=VERSION)
  21. parser.add_option("-b", "--bind",
  22. action="store", default="0.0.0.0:8000", dest="bind",
  23. help="Bind to address:port")
  24. opts, args = parser.parse_args()
  25. return opts, args
  26. ###
  27. ### Main
  28. ###
  29. def main():
  30. opts, args = parse_options()
  31. if ":" in opts.bind:
  32. address, port = opts.bind.split(":")
  33. port = int(port)
  34. else:
  35. address, port = opts.bind, 8000
  36. if args:
  37. x = args[0].split(":")
  38. if len(x) > 1:
  39. nodes = [(x[0], int(x[1]))]
  40. else:
  41. nodes = [(x[0], 8000)]
  42. else:
  43. nodes = []
  44. manager = Manager()
  45. debugger = Debugger()
  46. debugger.IgnoreEvents.extend(["Read", "Write"])
  47. manager += debugger
  48. bridge = Bridge(port, address=address, nodes=nodes)
  49. manager += bridge
  50. manager.run()
  51. ###
  52. ### Entry Point
  53. ###
  54. if __name__ == "__main__":
  55. main()