def main(): global config_server, config_server_port, config_password, config_method,\ config_fast_open logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version config_password = None config_method = None config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:', ['fast-open']) for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:', ['fast-open']) for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local_address'] = value elif key == '--fast-open': config['fast_open'] = True except getopt.GetoptError as e: logging.error(e) utils.print_local_help() sys.exit(2) config_server = config['server'] config_server_port = config['server_port'] config_local_port = config['local_port'] config_password = config['password'] config_method = config.get('method', None) config_local_address = config.get('local_address', '127.0.0.1') config_timeout = config.get('timeout', 600) config_fast_open = config.get('fast_open', False) if not config_password and not config_path: sys.exit('config not specified, please read ' 'https://github.com/clowwindy/shadowsocks') utils.check_config(config) encrypt.init_table(config_password, config_method) addrs = socket.getaddrinfo(config_local_address, config_local_port) if not addrs: logging.error('cant resolve listen address') sys.exit(1) ThreadingTCPServer.address_family = addrs[0][0] try: udprelay.UDPRelay(config_local_address, int(config_local_port), config_server, config_server_port, config_password, config_method, int(config_timeout), True).start() server = ThreadingTCPServer((config_local_address, config_local_port), Socks5Server) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): global SERVER, REMOTE_PORT, KEY, METHOD logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None LOCAL = '' IPv6 = False config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local'] = value elif key == '-6': IPv6 = True except getopt.GetoptError: utils.print_local_help() sys.exit(2) SERVER = config['server'] REMOTE_PORT = config['server_port'] PORT = config['local_port'] KEY = config['password'] METHOD = config.get('method', None) LOCAL = config.get('local', '127.0.0.1') if not KEY and not config_path: sys.exit( 'config not specified, please read https://github.com/clowwindy/shadowsocks' ) utils.check_config(config) encrypt.init_table(KEY, METHOD) try: if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 server = ThreadingTCPServer((LOCAL, PORT), Socks5Server) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): global config_server, config_server_port, config_password, config_method,\ config_fast_open, config_timeout logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version config_password = None config_method = None config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:t:', ['fast-open']) for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:t:', ['fast-open']) for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local_address'] = value elif key == '--fast-open': config['fast_open'] = True except getopt.GetoptError as e: logging.error(e) utils.print_local_help() sys.exit(2) config_server = config['server'] config_server_port = config['server_port'] config_local_port = config['local_port'] config_password = config['password'] config_method = config.get('method', None) config_local_address = config.get('local_address', '127.0.0.1') config_timeout = int(config.get('timeout', 300)) config_fast_open = config.get('fast_open', False) if not config_password and not config_path: sys.exit('config not specified, please read ' 'https://github.com/clowwindy/shadowsocks') utils.check_config(config) encrypt.init_table(config_password, config_method) addrs = socket.getaddrinfo(config_local_address, config_local_port) if not addrs: logging.error('cant resolve listen address') sys.exit(1) ThreadingTCPServer.address_family = addrs[0][0] try: udprelay.UDPRelay(config_local_address, int(config_local_port), config_server, config_server_port, config_password, config_method, int(config_timeout), True).start() server = ThreadingTCPServer((config_local_address, config_local_port), Socks5Server) server.timeout = int(config_timeout) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): global SERVER, REMOTE_PORT, KEY, METHOD logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None LOCAL = '' IPv6 = False config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local'] = value elif key == '-6': IPv6 = True except getopt.GetoptError: utils.print_local_help() sys.exit(2) SERVER = config['server'] REMOTE_PORT = config['server_port'] PORT = config['local_port'] KEY = config['password'] METHOD = config.get('method', None) LOCAL = config.get('local', '127.0.0.1') if not KEY and not config_path: sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks') utils.check_config(config) encrypt.init_table(KEY, METHOD) try: if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 server = ThreadingTCPServer((LOCAL, PORT), Socks5Server) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)