mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-25 20:37:48 +08:00
debug
This commit is contained in:
+7
-4
@@ -35,6 +35,7 @@ def update_data(data, infos):
|
|||||||
if not infos:
|
if not infos:
|
||||||
logger.log('ALERT', f'No valid resolved result')
|
logger.log('ALERT', f'No valid resolved result')
|
||||||
return data
|
return data
|
||||||
|
new_data = list()
|
||||||
for index, items in enumerate(data):
|
for index, items in enumerate(data):
|
||||||
if items.get('ip'):
|
if items.get('ip'):
|
||||||
continue
|
continue
|
||||||
@@ -42,11 +43,10 @@ def update_data(data, infos):
|
|||||||
record = infos.get(subdomain)
|
record = infos.get(subdomain)
|
||||||
if record:
|
if record:
|
||||||
items.update(record)
|
items.update(record)
|
||||||
|
new_data.append(items)
|
||||||
else:
|
else:
|
||||||
items['resolve'] = 0
|
subdomain = items.get('subdomain')
|
||||||
items['alive'] = 0
|
logger.log('DEBUG', f'{subdomain} resolution has no result')
|
||||||
items['reason'] = 'NoResult'
|
|
||||||
data[index] = items
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@@ -91,6 +91,7 @@ def gen_infos(data, qname, info, infos):
|
|||||||
info['ttl'] = ','.join(ttl)
|
info['ttl'] = ','.join(ttl)
|
||||||
infos[qname] = info
|
infos[qname] = info
|
||||||
if not flag:
|
if not flag:
|
||||||
|
logger.log('DEBUG', f'Resolving {qname} have not a record')
|
||||||
info['alive'] = 0
|
info['alive'] = 0
|
||||||
info['resolve'] = 0
|
info['resolve'] = 0
|
||||||
info['reason'] = 'NoARecord'
|
info['reason'] = 'NoARecord'
|
||||||
@@ -115,9 +116,11 @@ def deal_output(output_path):
|
|||||||
qname = items.get('name')[:-1] # 去除最右边的`.`点号
|
qname = items.get('name')[:-1] # 去除最右边的`.`点号
|
||||||
status = items.get('status')
|
status = items.get('status')
|
||||||
if status != 'NOERROR':
|
if status != 'NOERROR':
|
||||||
|
logger.log('DEBUG', f'Resolving {qname}: {status}')
|
||||||
continue
|
continue
|
||||||
data = items.get('data')
|
data = items.get('data')
|
||||||
if 'answers' not in data:
|
if 'answers' not in data:
|
||||||
|
logger.log('DEBUG', f'Resolving {qname} have not any answers')
|
||||||
info['alive'] = 0
|
info['alive'] = 0
|
||||||
info['resolve'] = 0
|
info['resolve'] = 0
|
||||||
info['reason'] = 'NoAnswer'
|
info['reason'] = 'NoAnswer'
|
||||||
|
|||||||
+30
-22
@@ -275,28 +275,38 @@ def is_valid_subdomain(ip=None, ip_num=None, cname=None, cname_num=None,
|
|||||||
def stat_times(data):
|
def stat_times(data):
|
||||||
times = dict()
|
times = dict()
|
||||||
for info in data:
|
for info in data:
|
||||||
ips = info.get('ip').split(',')
|
ip_str = info.get('ip')
|
||||||
for ip in ips:
|
if isinstance(ip_str, str):
|
||||||
value_one = times.setdefault(ip, 0)
|
ips = ip_str.split(',')
|
||||||
times[ip] = value_one + 1
|
for ip in ips:
|
||||||
cnames = info.get('cname').split(',')
|
value_one = times.setdefault(ip, 0)
|
||||||
for cname in cnames:
|
times[ip] = value_one + 1
|
||||||
value_two = times.setdefault(cname, 0)
|
cname_str = info.get('cname')
|
||||||
times[cname] = value_two + 1
|
if isinstance(cname_str, str):
|
||||||
|
cnames = cname_str.split(',')
|
||||||
|
for cname in cnames:
|
||||||
|
value_two = times.setdefault(cname, 0)
|
||||||
|
times[cname] = value_two + 1
|
||||||
return times
|
return times
|
||||||
|
|
||||||
|
|
||||||
def check_valid_subdomain(appear_times, cnames, ips):
|
def check_valid_subdomain(appear_times, info):
|
||||||
for cname in cnames:
|
ip_str = info.get('ip')
|
||||||
cname_num = appear_times.get(cname)
|
if ip_str:
|
||||||
isvalid, reason = is_valid_subdomain(cname=cname, cname_num=cname_num)
|
ips = ip_str.split(',')
|
||||||
if not isvalid:
|
for ip in ips:
|
||||||
return False, reason
|
ip_num = appear_times.get(ip)
|
||||||
for ip in ips:
|
isvalid, reason = is_valid_subdomain(ip=ip, ip_num=ip_num)
|
||||||
ip_num = appear_times.get(ip)
|
if not isvalid:
|
||||||
isvalid, reason = is_valid_subdomain(ip=ip, ip_num=ip_num)
|
return False, reason
|
||||||
if not isvalid:
|
cname_str = info.get('cname')
|
||||||
return False, reason
|
if cname_str:
|
||||||
|
cnames = cname_str.split(',')
|
||||||
|
for cname in cnames:
|
||||||
|
cname_num = appear_times.get(cname)
|
||||||
|
isvalid, reason = is_valid_subdomain(cname=cname, cname_num=cname_num)
|
||||||
|
if not isvalid:
|
||||||
|
return False, reason
|
||||||
return True, 'OK'
|
return True, 'OK'
|
||||||
|
|
||||||
|
|
||||||
@@ -305,9 +315,7 @@ def deal_wildcard(data):
|
|||||||
appear_times = stat_times(data)
|
appear_times = stat_times(data)
|
||||||
for info in data:
|
for info in data:
|
||||||
subdomain = info.get('subdomain')
|
subdomain = info.get('subdomain')
|
||||||
cnames = info.get('cname').split(',')
|
isvalid, reason = check_valid_subdomain(appear_times, info)
|
||||||
ips = info.get('ip').split(',')
|
|
||||||
isvalid, reason = check_valid_subdomain(appear_times, cnames, ips)
|
|
||||||
logger.log('DEBUG', f'{subdomain} is {isvalid} subdomain reason because {reason}')
|
logger.log('DEBUG', f'{subdomain} is {isvalid} subdomain reason because {reason}')
|
||||||
if isvalid:
|
if isvalid:
|
||||||
new_data.append(info)
|
new_data.append(info)
|
||||||
|
|||||||
Reference in New Issue
Block a user