|
@ -41,7 +41,19 @@ def proxyTest(rawInfo, startDelay = 1): |
|
|
''' |
|
|
''' |
|
|
代理检测入口 |
|
|
代理检测入口 |
|
|
|
|
|
|
|
|
异常错误: return None |
|
|
异常错误: |
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
启动失败: |
|
|
|
|
|
return { |
|
|
|
|
|
'success': False |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
测试完成: |
|
|
|
|
|
return { |
|
|
|
|
|
'success': True, |
|
|
|
|
|
'result': checkResult |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
''' |
|
|
''' |
|
|
if loadDir(workDir) == False: # 工作文件夹无效 |
|
|
if loadDir(workDir) == False: # 工作文件夹无效 |
|
@ -93,7 +105,7 @@ def proxyTest(rawInfo, startDelay = 1): |
|
|
'result': checkResult |
|
|
'result': checkResult |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def getTask(): # 从数据库中获取一项检测任务 |
|
|
def getTask(): # 获取检测任务 |
|
|
redisObject = redis.StrictRedis(host = redisHost, port = redisPort, db = 0) |
|
|
redisObject = redis.StrictRedis(host = redisHost, port = redisPort, db = 0) |
|
|
checkList = redisObject.keys(redisPrefix + 'check-a-*') # 优先级排序 |
|
|
checkList = redisObject.keys(redisPrefix + 'check-a-*') # 优先级排序 |
|
|
if len(checkList) == 0: |
|
|
if len(checkList) == 0: |
|
@ -110,21 +122,27 @@ def getTask(): # 从数据库中获取一项检测任务 |
|
|
key = checkList[0] # 选取首个任务 |
|
|
key = checkList[0] # 选取首个任务 |
|
|
taskContent = redisObject.get(key) |
|
|
taskContent = redisObject.get(key) |
|
|
redisObject.delete(key) |
|
|
redisObject.delete(key) |
|
|
return json.loads(taskContent) # JSON解码 |
|
|
tag = str(key[len(redisPrefix) + 8:], encoding = "utf-8") |
|
|
|
|
|
try: |
|
|
|
|
|
return tag, json.loads(taskContent) # JSON解码 |
|
|
|
|
|
except: # JSON解码失败 |
|
|
|
|
|
return tag, None |
|
|
|
|
|
|
|
|
def setResult(tag, result): # 向数据库中写入检测结果 |
|
|
def setResult(tag, result): # 写入检测结果 |
|
|
redisObject = redis.StrictRedis(host = redisHost, port = redisPort, db = 0) |
|
|
redisObject = redis.StrictRedis(host = redisHost, port = redisPort, db = 0) |
|
|
key = redisPrefix + 'result-' + tag |
|
|
key = redisPrefix + 'result-' + tag |
|
|
redisObject.set(key, json.dumps(result)) |
|
|
redisObject.set(key, json.dumps(result)) |
|
|
|
|
|
|
|
|
# ssInfo = '{"tag": "f43c9bae21ae8693", "check": ["http"], "info": {"type": "ss", "server": "127.0.0.1", "port": 12345, "password": "dnomd343", "method": "aes-256-ctr", "plugin": "", "pluginParam": ""}}' |
|
|
def main(): |
|
|
# ssrInfo = '{"tag": "54cd9ba3a8e86f93", "check": ["http"], "info": {"type": "ssr", "server": "127.0.0.1", "port": 23456, "password": "dnomd343", "method": "table", "protocol": "auth_aes128_md5", "protocolParam": "", "obfs": "tls1.2_ticket_auth", "obfsParam": ""}}' |
|
|
try: |
|
|
# redisObject = redis.StrictRedis(host = redisHost, port = redisPort, db = 0) |
|
|
taskTag, task = getTask() # 获取检测任务 |
|
|
# redisObject.set(redisPrefix + 'check-a-f43c9bae21ae8693', ssInfo) |
|
|
except: |
|
|
# redisObject.set(redisPrefix + 'check-c-54cd9ba3a8e86f93', ssrInfo) |
|
|
return |
|
|
|
|
|
if task == None: |
|
|
task = getTask() |
|
|
return |
|
|
if task == None: |
|
|
try: |
|
|
print("no task") |
|
|
setResult(taskTag, proxyTest(task)) # 检测并写入数据库 |
|
|
else: |
|
|
except: |
|
|
setResult(task['tag'], proxyTest(task)) |
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
main() |
|
|