mirror of https://github.com/dnomd343/ProxyC
Dnomd343
3 years ago
5 changed files with 98 additions and 97 deletions
@ -0,0 +1,80 @@ |
|||||
|
#!/usr/bin/python |
||||
|
# -*- coding:utf-8 -*- |
||||
|
|
||||
|
import json |
||||
|
import redis |
||||
|
import Checker |
||||
|
|
||||
|
def __loadRedis(redisHost = 'localhost', redisPort = 6379): # 连接Redis数据库 |
||||
|
return redis.StrictRedis(host = redisHost, port = redisPort, db = 0) |
||||
|
|
||||
|
def __getCheckInfo(redisObject, redisPrefix): |
||||
|
''' |
||||
|
获取检测任务 |
||||
|
|
||||
|
无任务或发生异常: |
||||
|
return None, None |
||||
|
|
||||
|
任务格式有误: |
||||
|
return tag, None |
||||
|
|
||||
|
任务获取成功: |
||||
|
return tag, {...} |
||||
|
''' |
||||
|
try: |
||||
|
checkList = redisObject.keys(redisPrefix + 'check-a-*') # 优先级排序 |
||||
|
if len(checkList) == 0: |
||||
|
checkList = redisObject.keys(redisPrefix + 'check-b-*') |
||||
|
if len(checkList) == 0: |
||||
|
checkList = redisObject.keys(redisPrefix + 'check-c-*') |
||||
|
if len(checkList) == 0: |
||||
|
checkList = redisObject.keys(redisPrefix + 'check-d-*') |
||||
|
if len(checkList) == 0: |
||||
|
checkList = redisObject.keys(redisPrefix + 'check-e-*') |
||||
|
if len(checkList) == 0: # 无任务 |
||||
|
return None, None |
||||
|
key = checkList[0] # 选取首个任务 |
||||
|
taskContent = redisObject.get(key) # 获取任务信息 |
||||
|
redisObject.delete(key) # 删除任务记录 |
||||
|
tag = str(key[len(redisPrefix) + 8:], encoding = "utf-8") # {prefix}check-x-{tag} |
||||
|
except: |
||||
|
return None, None |
||||
|
try: |
||||
|
return tag, json.loads(taskContent) # JSON解码 |
||||
|
except: # JSON解码失败 |
||||
|
return tag, None |
||||
|
|
||||
|
def __setCheckResult(checkTag, checkResult, redisObject, redisPrefix): # 写入检测结果 |
||||
|
try: |
||||
|
key = redisPrefix + 'result-' + checkTag |
||||
|
redisObject.set(key, json.dumps(checkResult)) |
||||
|
return True |
||||
|
except: |
||||
|
return False |
||||
|
|
||||
|
def main(startDelay, httpCheckUrl, httpCheckTimeout): |
||||
|
redisPrefix = 'proxyc-' |
||||
|
redisObject = __loadRedis() |
||||
|
checkTag, checkInfo = __getCheckInfo(redisObject, redisPrefix) # 获取检测任务 |
||||
|
if checkTag == None: |
||||
|
print("no task found") |
||||
|
return |
||||
|
print(checkInfo) |
||||
|
checkResult = Checker.proxyTest(checkInfo) |
||||
|
if checkResult == None: |
||||
|
print("some bad things happen") |
||||
|
return |
||||
|
elif checkResult['success'] == False: |
||||
|
print("error proxy info") |
||||
|
return |
||||
|
print(checkResult) |
||||
|
if __setCheckResult(checkTag, checkResult, redisObject, redisPrefix) == False: |
||||
|
print("redis write error") |
||||
|
return |
||||
|
print("ok") |
||||
|
|
||||
|
defaultStartDelay = 1 |
||||
|
defaultHttpCheckTimeout = 30 |
||||
|
defaultHttpCheckUrl = 'https://api.v2fly.org/checkConnection.svgz' |
||||
|
|
||||
|
main(defaultStartDelay, defaultHttpCheckUrl, defaultHttpCheckTimeout) |
@ -1,12 +0,0 @@ |
|||||
#!/usr/bin/python |
|
||||
# -*- coding:utf-8 -*- |
|
||||
|
|
||||
import ProxyDecoder as Decoder |
|
||||
|
|
||||
ssPlainUrl = 'ss://bf-cfb:test@192.168.100.1:8888' |
|
||||
ssCommonUrl = 'ss://YmYtY2ZiOnRlc3RAMTkyLjE2OC4xMDAuMTo4ODg4#example-server' |
|
||||
ssSip002Url = 'ss://cmM0LW1kNTpwYXNzd2Q@192.168.100.1:8888/?plugin=obfs-local%3Bobfs%3Dhttp#Example' |
|
||||
|
|
||||
ssrCommonUrl = 'ssr://ZmU4MDo6MTo2MDA0OmF1dGhfYWVzMTI4X21kNTphZXMtMjU2LWNmYjp0bHMxLjJfdGlja2V0X2F1dGg6Y0dGemMzZGsvP29iZnNwYXJhbT1ZMlUzTUdVeE5EY3dOekF1ZFhCa1lYUmxMbTFwWTNKdmMyOW1kQzVqYjIwJnByb3RvcGFyYW09TVRRM01EY3dPa0pGTTIxck9RJnJlbWFya3M9UlZoQlRWQk1SUSZncm91cD1kR1Z6ZEE' |
|
||||
|
|
||||
print(Decoder.decode(ssrCommonUrl)) |
|
@ -1,28 +0,0 @@ |
|||||
#!/usr/bin/python |
|
||||
# -*- coding:utf-8 -*- |
|
||||
|
|
||||
import ProxyFilter as Filter |
|
||||
|
|
||||
ssInfo = { |
|
||||
"type": "ss", |
|
||||
"server": "127.0.0.1 ", |
|
||||
"port": 12345, |
|
||||
"password": "dnomd343", |
|
||||
"method": "aes_256-ctr", |
|
||||
"plugin": "obfs", |
|
||||
"pluginParam": "obfs=http;host=www.bing.com" |
|
||||
} |
|
||||
|
|
||||
ssrInfo = { |
|
||||
"type": "ssr", |
|
||||
"server": " 127.0.0.1", |
|
||||
"port": 23456, |
|
||||
"password": "dnomd343", |
|
||||
"method": "table", |
|
||||
"protocol": "auth-aes128_md5", |
|
||||
"protocolParam": "", |
|
||||
"obfs": "", |
|
||||
"obfsParam": "fafadfaf" |
|
||||
} |
|
||||
|
|
||||
print(Filter.filter(ssrInfo)) |
|
Loading…
Reference in new issue