mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-10-27 10:55:51 +08:00
修复resolve标记有误问题
This commit is contained in:
+44
-39
@@ -25,25 +25,30 @@ def filter_subdomain(data):
|
|||||||
return subdomains
|
return subdomains
|
||||||
|
|
||||||
|
|
||||||
def update_data(data, records):
|
def update_data(data, infos):
|
||||||
"""
|
"""
|
||||||
更新解析结果
|
更新解析结果
|
||||||
|
|
||||||
:param list data: 待更新的数据列表
|
:param list data: 待更新的数据列表
|
||||||
:param dict records: 解析结果字典
|
:param dict infos: 子域有关结果信息
|
||||||
:return: 更新后的数据列表
|
:return: 更新后的数据列表
|
||||||
"""
|
"""
|
||||||
logger.log('DEBUG', f'Updating resolved results')
|
logger.log('DEBUG', f'Updating resolved results')
|
||||||
if not records:
|
if not infos:
|
||||||
logger.log('ERROR', f'No valid resolved result')
|
logger.log('ERROR', f'No valid resolved result')
|
||||||
return data
|
return data
|
||||||
for index, items in enumerate(data):
|
for index, items in enumerate(data):
|
||||||
if not items.get('content'):
|
if items.get('content'):
|
||||||
subdomain = items.get('subdomain')
|
continue
|
||||||
record = records.get(subdomain)
|
subdomain = items.get('subdomain')
|
||||||
if record:
|
record = infos.get(subdomain)
|
||||||
items.update(record)
|
if record:
|
||||||
data[index] = items
|
items.update(record)
|
||||||
|
else:
|
||||||
|
items['resolve'] = 0
|
||||||
|
items['alive'] = 0
|
||||||
|
items['reason'] = 'NORECORD'
|
||||||
|
data[index] = items
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +73,7 @@ def save_subdomains(save_path, subdomain_list):
|
|||||||
|
|
||||||
def deal_output(output_path):
|
def deal_output(output_path):
|
||||||
logger.log('INFOR', f'Processing resolved results')
|
logger.log('INFOR', f'Processing resolved results')
|
||||||
records = dict() # 用来记录所有域名解析数据
|
infos = dict() # 用来记录所有域名有关信息
|
||||||
ip_asn = IPAsnInfo()
|
ip_asn = IPAsnInfo()
|
||||||
ip_geo = IpGeoInfo()
|
ip_geo = IpGeoInfo()
|
||||||
db_path = settings.data_storage_dir.joinpath('ip2region.db')
|
db_path = settings.data_storage_dir.joinpath('ip2region.db')
|
||||||
@@ -82,22 +87,22 @@ def deal_output(output_path):
|
|||||||
logger.log('ERROR', e.args)
|
logger.log('ERROR', e.args)
|
||||||
logger.log('ERROR', f'Error resolve line {line}, skip this line')
|
logger.log('ERROR', f'Error resolve line {line}, skip this line')
|
||||||
continue
|
continue
|
||||||
record = dict()
|
info = dict()
|
||||||
record['resolver'] = items.get('resolver')
|
info['resolver'] = items.get('resolver')
|
||||||
qname = items.get('name')[:-1] # 去除最右边的`.`点号
|
qname = items.get('name')[:-1] # 去除最右边的`.`点号
|
||||||
status = items.get('status')
|
status = items.get('status')
|
||||||
if status != 'NOERROR':
|
if status != 'NOERROR':
|
||||||
record['alive'] = 0
|
info['alive'] = 0
|
||||||
record['resolve'] = 0
|
info['resolve'] = 0
|
||||||
record['reason'] = status
|
info['reason'] = status
|
||||||
records[qname] = record
|
infos[qname] = info
|
||||||
continue
|
continue
|
||||||
data = items.get('data')
|
data = items.get('data')
|
||||||
if 'answers' not in data:
|
if 'answers' not in data:
|
||||||
record['alive'] = 0
|
info['alive'] = 0
|
||||||
record['resolve'] = 0
|
info['resolve'] = 0
|
||||||
record['reason'] = 'NOANSWER'
|
info['reason'] = 'NOANSWER'
|
||||||
records[qname] = record
|
infos[qname] = info
|
||||||
continue
|
continue
|
||||||
flag = False
|
flag = False
|
||||||
cname = list()
|
cname = list()
|
||||||
@@ -130,24 +135,24 @@ def deal_output(output_path):
|
|||||||
locs.append(loc)
|
locs.append(loc)
|
||||||
reg = ip_reg.memory_search(ip).get('region').decode('utf-8')
|
reg = ip_reg.memory_search(ip).get('region').decode('utf-8')
|
||||||
regs.append(reg)
|
regs.append(reg)
|
||||||
record['resolve'] = 1
|
info['resolve'] = 1
|
||||||
record['reason'] = status
|
info['reason'] = status
|
||||||
record['cname'] = ','.join(cname)
|
info['cname'] = ','.join(cname)
|
||||||
record['content'] = ','.join(ips)
|
info['content'] = ','.join(ips)
|
||||||
record['public'] = ','.join(public)
|
info['public'] = ','.join(public)
|
||||||
record['ttl'] = ','.join(ttls)
|
info['ttl'] = ','.join(ttls)
|
||||||
record['cidr'] = ','.join(cidrs)
|
info['cidr'] = ','.join(cidrs)
|
||||||
record['asn'] = ','.join(asns)
|
info['asn'] = ','.join(asns)
|
||||||
record['org'] = ','.join(orgs)
|
info['org'] = ','.join(orgs)
|
||||||
record['ip2location'] = ','.join(locs)
|
info['ip2location'] = ','.join(locs)
|
||||||
record['ip2region'] = ','.join(regs)
|
info['ip2region'] = ','.join(regs)
|
||||||
records[qname] = record
|
infos[qname] = info
|
||||||
if not flag:
|
if not flag:
|
||||||
record['alive'] = 0
|
info['alive'] = 0
|
||||||
record['resolve'] = 0
|
info['resolve'] = 0
|
||||||
record['reason'] = 'NOARECORD'
|
info['reason'] = 'NOARECORD'
|
||||||
records[qname] = record
|
infos[qname] = info
|
||||||
return records
|
return infos
|
||||||
|
|
||||||
|
|
||||||
def run_resolve(domain, data):
|
def run_resolve(domain, data):
|
||||||
@@ -187,7 +192,7 @@ def run_resolve(domain, data):
|
|||||||
utils.call_massdns(massdns_path, save_path, ns_path,
|
utils.call_massdns(massdns_path, save_path, ns_path,
|
||||||
output_path, log_path, quiet_mode=True)
|
output_path, log_path, quiet_mode=True)
|
||||||
|
|
||||||
records = deal_output(output_path)
|
infos = deal_output(output_path)
|
||||||
data = update_data(data, records)
|
data = update_data(data, infos)
|
||||||
logger.log('INFOR', f'Finished resolve subdomains of {domain}')
|
logger.log('INFOR', f'Finished resolve subdomains of {domain}')
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user