Merge dda8326592
into 8a3adfc344
This commit is contained in:
commit
8910cb1db9
3 changed files with 42 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"server":"localhost",
|
"server":"localhost",
|
||||||
"server_port":8388,
|
"port":8388,
|
||||||
"local_port":1080,
|
"localport":1080,
|
||||||
"password":"barfoo!",
|
"password":"barfoo!",
|
||||||
"timeout":60
|
"timeout":60
|
||||||
}
|
}
|
||||||
|
|
36
local.py
36
local.py
|
@ -31,7 +31,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import getopt
|
import argparse
|
||||||
|
|
||||||
def get_table(key):
|
def get_table(key):
|
||||||
m = hashlib.md5()
|
m = hashlib.md5()
|
||||||
|
@ -125,21 +125,27 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
with open('config.json', 'rb') as f:
|
with open('config.json', 'rb') as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
SERVER = config['server']
|
|
||||||
REMOTE_PORT = config['server_port']
|
|
||||||
PORT = config['local_port']
|
|
||||||
KEY = config['password']
|
|
||||||
|
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:l:')
|
parser = argparse.ArgumentParser(
|
||||||
for key, value in optlist:
|
description='ShadowSocks Client'
|
||||||
if key == '-p':
|
)
|
||||||
REMOTE_PORT = int(value)
|
parser.add_argument('-p', '--port', action='store', help='remote port', type=int)
|
||||||
elif key == '-k':
|
parser.add_argument('-k', '--key', action='store', help='password', type=unicode)
|
||||||
KEY = value
|
parser.add_argument('-l', '--localport', action='store', help='local port', type=int)
|
||||||
elif key == '-l':
|
parser.add_argument('-s', '--server', action='store', help='server ip address', type=unicode)
|
||||||
PORT = int(value)
|
if not len(sys.argv):
|
||||||
elif key == '-s':
|
parser.print_help()
|
||||||
SERVER = value
|
sys.exit(1)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
d = vars(args)
|
||||||
|
_config = dict((k,d[k]) for k in d if d[k])
|
||||||
|
config.update(_config)
|
||||||
|
|
||||||
|
SERVER = config['server']
|
||||||
|
REMOTE_PORT = config['port']
|
||||||
|
PORT = config['localport']
|
||||||
|
KEY = config['password']
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
|
||||||
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
|
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
|
||||||
|
|
29
server.py
29
server.py
|
@ -31,7 +31,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import getopt
|
import argparse
|
||||||
|
|
||||||
def get_table(key):
|
def get_table(key):
|
||||||
m = hashlib.md5()
|
m = hashlib.md5()
|
||||||
|
@ -102,16 +102,24 @@ if __name__ == '__main__':
|
||||||
with open('config.json', 'rb') as f:
|
with open('config.json', 'rb') as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
|
|
||||||
SERVER = config['server']
|
parser = argparse.ArgumentParser(
|
||||||
PORT = config['server_port']
|
description='ShadowSocks Server'
|
||||||
KEY = config['password']
|
)
|
||||||
|
parser.add_argument('-p', '--port', action='store', help='port', type=int)
|
||||||
|
parser.add_argument('-k', '--key', action='store', help='password', type=unicode)
|
||||||
|
if not len(sys.argv):
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], 'p:k:')
|
args = parser.parse_args()
|
||||||
for key, value in optlist:
|
d = vars(args)
|
||||||
if key == '-p':
|
_config = dict((k,d[k]) for k in d if d[k])
|
||||||
PORT = int(value)
|
|
||||||
elif key == '-k':
|
config.update(_config)
|
||||||
KEY = value
|
|
||||||
|
SERVER = config['server']
|
||||||
|
PORT = config['port']
|
||||||
|
KEY = config['password']
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
|
||||||
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
|
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
|
||||||
|
@ -127,4 +135,3 @@ if __name__ == '__main__':
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue