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.

socks.py 1.3KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. I am a support module for making SOCKSv4 servers with twistd.
  5. """
  6. from __future__ import print_function
  7. from twisted.protocols import socks
  8. from twisted.python import usage
  9. from twisted.application import internet
  10. class Options(usage.Options):
  11. synopsis = "[-i <interface>] [-p <port>] [-l <file>]"
  12. optParameters = [["interface", "i", "127.0.0.1", "local interface to which we listen"],
  13. ["port", "p", 1080, "Port on which to listen"],
  14. ["log", "l", None, "file to log connection data to"]]
  15. compData = usage.Completions(
  16. optActions={"log": usage.CompleteFiles("*.log"),
  17. "interface": usage.CompleteNetInterfaces()}
  18. )
  19. longdesc = "Makes a SOCKSv4 server."
  20. def makeService(config):
  21. if config["interface"] != "127.0.0.1":
  22. print()
  23. print("WARNING:")
  24. print(" You have chosen to listen on a non-local interface.")
  25. print(" This may allow intruders to access your local network")
  26. print(" if you run this on a firewall.")
  27. print()
  28. t = socks.SOCKSv4Factory(config['log'])
  29. portno = int(config['port'])
  30. return internet.TCPServer(portno, t, interface=config['interface'])