portforward.py 775 B

1234567891011121314151617181920212223242526
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Support module for making a port forwarder with twistd.
  5. """
  6. from twisted.application import strports
  7. from twisted.protocols import portforward
  8. from twisted.python import usage
  9. class Options(usage.Options):
  10. synopsis = "[options]"
  11. longdesc = "Port Forwarder."
  12. optParameters = [
  13. ["port", "p", "6666", "Set the port number."],
  14. ["host", "h", "localhost", "Set the host."],
  15. ["dest_port", "d", 6665, "Set the destination port."],
  16. ]
  17. compData = usage.Completions(optActions={"host": usage.CompleteHostnames()})
  18. def makeService(config):
  19. f = portforward.ProxyFactory(config["host"], int(config["dest_port"]))
  20. return strports.service(config["port"], f)