From adc103295bf12972e8d93dfef96704b3e73a2f30 Mon Sep 17 00:00:00 2001 From: nopriest Date: Mon, 23 Apr 2018 14:23:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E6=B5=8B=E6=9C=89?= =?UTF-8?q?=E6=95=88=E6=80=A7=E4=B8=BA=E9=97=AA=E5=85=89=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 3 ++- db/DataStore.py | 7 ++++++- db/SqlHelper.py | 2 +- requirements.txt | 1 - start.bat | 2 +- validator/Validator.py | 21 ++++++++++++++++++++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 389dc74..9645fae 100644 --- a/config.py +++ b/config.py @@ -196,7 +196,8 @@ def get_header(): #因此在这个地方用户可以自己添加检测函数,我以百度为访问网址尝试一下 #大家可以看一下Validator.py文件中的baidu_check函数和detect_proxy函数就会明白 -CHECK_PROXY={'function':'checkProxy'}#{'function':'baidu_check'} +#CHECK_PROXY={'function':'checkProxy'}#{'function':'baidu_check'} +CHECK_PROXY={'function':'bloodwow_check'} #下面配置squid,现在还没实现 #SQUID={'path':None,'confpath':'C:/squid/etc/squid.conf'} diff --git a/db/DataStore.py b/db/DataStore.py index 5b8ec92..c1dcd74 100644 --- a/db/DataStore.py +++ b/db/DataStore.py @@ -1,5 +1,10 @@ # coding:utf-8 -import sys +import sys,os + +BASE_DIR = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) +if BASE_DIR not in sys.path: + sys.path.append(BASE_DIR) + from config import DB_CONFIG from util.exception import Con_DB_Fail diff --git a/db/SqlHelper.py b/db/SqlHelper.py index 8df7b1a..dd7ab35 100644 --- a/db/SqlHelper.py +++ b/db/SqlHelper.py @@ -140,7 +140,7 @@ def close(self): if __name__ == '__main__': sqlhelper = SqlHelper() sqlhelper.init_db() - proxy = {'ip': '192.168.1.1', 'port': 80, 'type': 0, 'protocol': 0, 'country': '中国', 'area': '广州', 'speed': 11.123, 'types': ''} + proxy = {'ip': '192.168.1.1', 'port': 80, 'type': 0, 'protocol': 0, 'country': 'cn', 'area': 'gz', 'speed': 11.123, 'types': ''} sqlhelper.insert(proxy) sqlhelper.update({'ip': '192.168.1.1', 'port': 80}, {'score': 10}) print(sqlhelper.select(1)) diff --git a/requirements.txt b/requirements.txt index 89289da..c14b822 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,5 @@ greenlet==0.4.11 lxml==3.7.1 requests==2.12.4 SQLAlchemy==1.1.4 -web.py==0.38 redis==2.10.5 psutil diff --git a/start.bat b/start.bat index 121bf6b..25d1e4a 100644 --- a/start.bat +++ b/start.bat @@ -1 +1 @@ -py -2 IPProxy.py \ No newline at end of file +python IPProxy.py \ No newline at end of file diff --git a/validator/Validator.py b/validator/Validator.py index 46bc444..4de0365 100644 --- a/validator/Validator.py +++ b/validator/Validator.py @@ -211,8 +211,27 @@ def getMyIP(): except Exception as e: raise Test_URL_Fail +def bloodwow_check(selfip,proxies): + try: + start = time.time() + r = requests.get(url='http://dx.blood-wow.com:85/', headers=config.get_header(), timeout=config.TIMEOUT, proxies=proxies) + r.encoding = chardet.detect(r.content)['encoding'] + if r.ok: + speed = round(time.time() - start, 2) + protocol= 0 + types=0 + + else: + speed = -1 + protocol= -1 + types=-1 + except Exception as e: + speed = -1 + protocol = -1 + types = -1 + return protocol, types, speed -if __name__ == '__main__': +if __name__ == '__main__': ip = '222.186.161.132' port = 3128 proxies = {"http": "http://%s:%s" % (ip, port), "https": "http://%s:%s" % (ip, port)}