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:
|
||||
logger.log('ALERT', f'No valid resolved result')
|
||||
return data
|
||||
new_data = list()
|
||||
for index, items in enumerate(data):
|
||||
if items.get('ip'):
|
||||
continue
|
||||
@@ -42,11 +43,10 @@ def update_data(data, infos):
|
||||
record = infos.get(subdomain)
|
||||
if record:
|
||||
items.update(record)
|
||||
new_data.append(items)
|
||||
else:
|
||||
items['resolve'] = 0
|
||||
items['alive'] = 0
|
||||
items['reason'] = 'NoResult'
|
||||
data[index] = items
|
||||
subdomain = items.get('subdomain')
|
||||
logger.log('DEBUG', f'{subdomain} resolution has no result')
|
||||
return data
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ def gen_infos(data, qname, info, infos):
|
||||
info['ttl'] = ','.join(ttl)
|
||||
infos[qname] = info
|
||||
if not flag:
|
||||
logger.log('DEBUG', f'Resolving {qname} have not a record')
|
||||
info['alive'] = 0
|
||||
info['resolve'] = 0
|
||||
info['reason'] = 'NoARecord'
|
||||
@@ -115,9 +116,11 @@ def deal_output(output_path):
|
||||
qname = items.get('name')[:-1] # 去除最右边的`.`点号
|
||||
status = items.get('status')
|
||||
if status != 'NOERROR':
|
||||
logger.log('DEBUG', f'Resolving {qname}: {status}')
|
||||
continue
|
||||
data = items.get('data')
|
||||
if 'answers' not in data:
|
||||
logger.log('DEBUG', f'Resolving {qname} have not any answers')
|
||||
info['alive'] = 0
|
||||
info['resolve'] = 0
|
||||
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):
|
||||
times = dict()
|
||||
for info in data:
|
||||
ips = info.get('ip').split(',')
|
||||
for ip in ips:
|
||||
value_one = times.setdefault(ip, 0)
|
||||
times[ip] = value_one + 1
|
||||
cnames = info.get('cname').split(',')
|
||||
for cname in cnames:
|
||||
value_two = times.setdefault(cname, 0)
|
||||
times[cname] = value_two + 1
|
||||
ip_str = info.get('ip')
|
||||
if isinstance(ip_str, str):
|
||||
ips = ip_str.split(',')
|
||||
for ip in ips:
|
||||
value_one = times.setdefault(ip, 0)
|
||||
times[ip] = value_one + 1
|
||||
cname_str = info.get('cname')
|
||||
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
|
||||
|
||||
|
||||
def check_valid_subdomain(appear_times, cnames, ips):
|
||||
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
|
||||
for ip in ips:
|
||||
ip_num = appear_times.get(ip)
|
||||
isvalid, reason = is_valid_subdomain(ip=ip, ip_num=ip_num)
|
||||
if not isvalid:
|
||||
return False, reason
|
||||
def check_valid_subdomain(appear_times, info):
|
||||
ip_str = info.get('ip')
|
||||
if ip_str:
|
||||
ips = ip_str.split(',')
|
||||
for ip in ips:
|
||||
ip_num = appear_times.get(ip)
|
||||
isvalid, reason = is_valid_subdomain(ip=ip, ip_num=ip_num)
|
||||
if not isvalid:
|
||||
return False, reason
|
||||
cname_str = info.get('cname')
|
||||
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'
|
||||
|
||||
|
||||
@@ -305,9 +315,7 @@ def deal_wildcard(data):
|
||||
appear_times = stat_times(data)
|
||||
for info in data:
|
||||
subdomain = info.get('subdomain')
|
||||
cnames = info.get('cname').split(',')
|
||||
ips = info.get('ip').split(',')
|
||||
isvalid, reason = check_valid_subdomain(appear_times, cnames, ips)
|
||||
isvalid, reason = check_valid_subdomain(appear_times, info)
|
||||
logger.log('DEBUG', f'{subdomain} is {isvalid} subdomain reason because {reason}')
|
||||
if isvalid:
|
||||
new_data.append(info)
|
||||
|
||||
Reference in New Issue
Block a user