diff --git a/Checker.py b/Checker.py index a12d91a..10c48f8 100644 --- a/Checker.py +++ b/Checker.py @@ -39,7 +39,7 @@ def proxyTest( startDelay = 1, workDir = '/tmp/ProxyC', httpCheckUrl = 'http://gstatic.com/generate_204', - httpCheckTimeout = 12, + httpCheckTimeout = 20, ): ''' 代理检测入口 diff --git a/Loop.py b/Loop.py new file mode 100644 index 0000000..32bdc45 --- /dev/null +++ b/Loop.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + +import time +import redis +import subprocess + +maxThread = 32 + +redisPort = 6379 +redisHost = 'localhost' +redisPrefix = 'proxyc-' + +redisObject = redis.StrictRedis( + db = 0, + host = redisHost, + port = redisPort +) + +processList = [] +while True: + spareNum = min( + maxThread - len(processList), # 空余进程数 + len(redisObject.keys(redisPrefix + 'check-*')) # 待检测个数 + ) + if spareNum < 0: + spareNum = 0 + print("spareNum = " + str(spareNum)) + + for i in range(spareNum): # 运行检测进程 + processList.append( + subprocess.Popen(['python','Run.py']) + ) + time.sleep(0.2) + + for process in processList: # 遍历子进程 + if process.poll() != None: # 进程已退出 + print("remove subprocess") + processList.remove(process) + + time.sleep(0.5) diff --git a/ProxyChecker/Http.py b/ProxyChecker/Http.py index 5eaca0c..b8c1243 100644 --- a/ProxyChecker/Http.py +++ b/ProxyChecker/Http.py @@ -54,7 +54,9 @@ def httpCheck(port, url = 'http://gstatic.com/generate_204', timeout = 30): ''' result = [] failNum = 0 + timeout = timeout * 64 / 119 # 4/64 + 2/64 + 1/64 + 1/4 + 1/2 + 1/1 for i in [4, 2, 1]: # 三次测试 + time.sleep(timeout / 64 * i) status, delay = httpPing(port, url, timeout / i) if status == None: # 测试异常 return None, delay diff --git a/Run.py b/Run.py index 85b057b..1720d6b 100644 --- a/Run.py +++ b/Run.py @@ -60,7 +60,12 @@ def main(startDelay, httpCheckUrl, httpCheckTimeout): print("no task found") return print(checkInfo) - checkResult = Checker.proxyTest(checkInfo) + checkResult = Checker.proxyTest( + checkInfo, + startDelay = startDelay, + httpCheckUrl = httpCheckUrl, + httpCheckTimeout = httpCheckTimeout + ) if checkResult == None: print("some bad things happen") return @@ -73,8 +78,8 @@ def main(startDelay, httpCheckUrl, httpCheckTimeout): return print("ok") -defaultStartDelay = 1 -defaultHttpCheckTimeout = 30 -defaultHttpCheckUrl = 'https://api.v2fly.org/checkConnection.svgz' +defaultStartDelay = 1.5 +defaultHttpCheckTimeout = 20 +defaultHttpCheckUrl = 'http://gstatic.com/generate_204' main(defaultStartDelay, defaultHttpCheckUrl, defaultHttpCheckTimeout) diff --git a/Web.py b/Web.py index ac3cc16..74dc4fb 100644 --- a/Web.py +++ b/Web.py @@ -144,6 +144,7 @@ def getTaskInfo(checkId): # 获取任务详情 'success': True, 'complete': True, 'checkId': checkId, + 'number': len(taskInfo['proxy']), 'result': taskInfo['result'] } @@ -156,7 +157,8 @@ def getTaskInfo(checkId): # 获取任务详情 'success': True, 'complete': False, 'checkId': checkId, - 'schedule': format(completeNum / len(taskInfo['proxy']), '.2f') + 'number': len(taskInfo['proxy']), + 'schedule': round(completeNum / len(taskInfo['proxy']), 2) } checkResult = [] @@ -174,6 +176,7 @@ def getTaskInfo(checkId): # 获取任务详情 'success': True, 'complete': True, 'checkId': checkId, + 'number': len(taskInfo['proxy']), 'result': taskInfo['result'] } except: diff --git a/redisTest.py b/redisTest.py deleted file mode 100644 index 0ffdc8b..0000000 --- a/redisTest.py +++ /dev/null @@ -1,11 +0,0 @@ -import redis - -redisPrefix = 'proxyc-' -redisHost = 'localhost' -redisPort = 6379 - -ssInfo = '{"tag": "f43c9bae21ae8693", "check": ["http"], "info": {"type": "ss", "server": "127.0.0.1", "port": 12345, "password": "dnomd343", "method": "aes-256-ctr", "plugin": "", "pluginParam": ""}}' -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": ""}}' -redisObject = redis.StrictRedis(host = redisHost, port = redisPort, db = 0) -redisObject.set(redisPrefix + 'check-a-f43c9bae21ae8693', ssInfo) -redisObject.set(redisPrefix + 'check-c-54cd9ba3a8e86f93', ssrInfo)