portforward.py 795 B

123456789101112131415161718192021222324252627
  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.protocols import portforward
  7. from twisted.python import usage
  8. from twisted.application import strports
  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(
  18. optActions={"host": usage.CompleteHostnames()}
  19. )
  20. def makeService(config):
  21. f = portforward.ProxyFactory(config['host'], int(config['dest_port']))
  22. return strports.service(config['port'], f)