增加HEAD请求异常处理

This commit is contained in:
shmilylty
2019-11-06 01:09:30 +08:00
parent a987b9d96c
commit 3e19062670
2 changed files with 36 additions and 6 deletions
+29 -2
View File
@@ -15,7 +15,6 @@ from . import utils
from .domain import Domain from .domain import Domain
from common.database import Database from common.database import Database
lock = threading.Lock() lock = threading.Lock()
@@ -66,6 +65,34 @@ class Module(object):
logger.log('DEBUG', f'{self.source}模块发现{self.domain}的子域\n' logger.log('DEBUG', f'{self.source}模块发现{self.domain}的子域\n'
f'{self.subdomains}') f'{self.subdomains}')
def head(self, url, params=None, check=True, **kwargs):
"""
自定义head请求
:param str url: 请求地址
:param dict params: 请求参数
:param bool check: 检查响应
:param kwargs: 其他参数
:return: requests响应对象
"""
try:
resp = requests.head(url,
params=params,
cookies=self.cookie,
headers=self.header,
proxies=self.proxy,
timeout=self.timeout,
verify=self.verify,
**kwargs)
except Exception as e:
logger.log('ERROR', e)
return None
if not check:
return resp
if utils.check_response('HEAD', resp):
return resp
return None
def get(self, url, params=None, check=True, **kwargs): def get(self, url, params=None, check=True, **kwargs):
""" """
自定义get请求 自定义get请求
@@ -118,7 +145,7 @@ class Module(object):
return None return None
if not check: if not check:
return resp return resp
if utils.check_response('GET', resp): if utils.check_response('POST', resp):
return resp return resp
return None return None
+5 -2
View File
@@ -47,7 +47,10 @@ class Search(Module):
:return: 匹配的子域 :return: 匹配的子域
:rtype set :rtype set
""" """
resp = requests.head(url, headers=self.header, proxies=self.proxy, resp = self.head(url, allow_redirects=False)
timeout=self.timeout, allow_redirects=False) if not resp:
return set()
location = resp.headers.get('location') location = resp.headers.get('location')
if not location:
return set()
return set(utils.match_subdomain(domain, location)) return set(utils.match_subdomain(domain, location))