mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-10-30 05:05:51 +08:00
重构deal_output函数
This commit is contained in:
+37
-30
@@ -9,6 +9,12 @@ from common.ipgeo import IpGeoInfo
|
|||||||
from common.ipreg import IpRegInfo
|
from common.ipreg import IpRegInfo
|
||||||
|
|
||||||
|
|
||||||
|
ip_asn = IPAsnInfo()
|
||||||
|
ip_geo = IpGeoInfo()
|
||||||
|
db_path = settings.data_storage_dir.joinpath('ip2region.db')
|
||||||
|
ip_reg = IpRegInfo(db_path)
|
||||||
|
|
||||||
|
|
||||||
def filter_subdomain(data):
|
def filter_subdomain(data):
|
||||||
"""
|
"""
|
||||||
过滤出无解析内容的子域到新的子域列表
|
过滤出无解析内容的子域到新的子域列表
|
||||||
@@ -71,35 +77,7 @@ def save_subdomains(save_path, subdomain_list):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def deal_output(output_path):
|
def gen_infos(data, qname, info, infos):
|
||||||
logger.log('INFOR', f'Processing resolved results')
|
|
||||||
infos = dict() # 用来记录所有域名有关信息
|
|
||||||
ip_asn = IPAsnInfo()
|
|
||||||
ip_geo = IpGeoInfo()
|
|
||||||
db_path = settings.data_storage_dir.joinpath('ip2region.db')
|
|
||||||
ip_reg = IpRegInfo(db_path)
|
|
||||||
with open(output_path) as fd:
|
|
||||||
for line in fd:
|
|
||||||
line = line.strip()
|
|
||||||
try:
|
|
||||||
items = json.loads(line)
|
|
||||||
except Exception as e:
|
|
||||||
logger.log('ERROR', e.args)
|
|
||||||
logger.log('ERROR', f'Error resolve line {line}, skip this line')
|
|
||||||
continue
|
|
||||||
info = dict()
|
|
||||||
info['resolver'] = items.get('resolver')
|
|
||||||
qname = items.get('name')[:-1] # 去除最右边的`.`点号
|
|
||||||
status = items.get('status')
|
|
||||||
if status != 'NOERROR':
|
|
||||||
continue
|
|
||||||
data = items.get('data')
|
|
||||||
if 'answers' not in data:
|
|
||||||
info['alive'] = 0
|
|
||||||
info['resolve'] = 0
|
|
||||||
info['reason'] = 'NoAnswer'
|
|
||||||
infos[qname] = info
|
|
||||||
continue
|
|
||||||
flag = False
|
flag = False
|
||||||
cname = list()
|
cname = list()
|
||||||
ips = list()
|
ips = list()
|
||||||
@@ -132,7 +110,7 @@ def deal_output(output_path):
|
|||||||
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)
|
||||||
info['resolve'] = 1
|
info['resolve'] = 1
|
||||||
info['reason'] = status
|
info['reason'] = 'OK'
|
||||||
info['cname'] = ','.join(cname)
|
info['cname'] = ','.join(cname)
|
||||||
info['content'] = ','.join(ips)
|
info['content'] = ','.join(ips)
|
||||||
info['public'] = ','.join(public)
|
info['public'] = ','.join(public)
|
||||||
@@ -151,6 +129,35 @@ def deal_output(output_path):
|
|||||||
return infos
|
return infos
|
||||||
|
|
||||||
|
|
||||||
|
def deal_output(output_path):
|
||||||
|
logger.log('INFOR', f'Processing resolved results')
|
||||||
|
infos = dict() # 用来记录所有域名有关信息
|
||||||
|
with open(output_path) as fd:
|
||||||
|
for line in fd:
|
||||||
|
line = line.strip()
|
||||||
|
try:
|
||||||
|
items = json.loads(line)
|
||||||
|
except Exception as e:
|
||||||
|
logger.log('ERROR', e.args)
|
||||||
|
logger.log('ERROR', f'Error resolve line {line}, skip this line')
|
||||||
|
continue
|
||||||
|
info = dict()
|
||||||
|
info['resolver'] = items.get('resolver')
|
||||||
|
qname = items.get('name')[:-1] # 去除最右边的`.`点号
|
||||||
|
status = items.get('status')
|
||||||
|
if status != 'NOERROR':
|
||||||
|
continue
|
||||||
|
data = items.get('data')
|
||||||
|
if 'answers' not in data:
|
||||||
|
info['alive'] = 0
|
||||||
|
info['resolve'] = 0
|
||||||
|
info['reason'] = 'NoAnswer'
|
||||||
|
infos[qname] = info
|
||||||
|
continue
|
||||||
|
infos = gen_infos(data, qname, info, infos)
|
||||||
|
return infos
|
||||||
|
|
||||||
|
|
||||||
def run_resolve(domain, data):
|
def run_resolve(domain, data):
|
||||||
"""
|
"""
|
||||||
调用子域解析入口函数
|
调用子域解析入口函数
|
||||||
|
|||||||
Reference in New Issue
Block a user