使用侦察工具,输出列表列表,其中大多数包含一个子域及其各自的主机地址。我正在尝试使列表更整洁,仅包含子域和IP,而不包含后台输出。下面是将原始输出解析为较小列表的示例,以及使用正则表达式尝试提取子域和IP地址的方法。但是,无论我尝试使用正则表达式格式还是re。我通常会收到“ TypeError:预期的字符串或类似字节的对象”
单个列表的所需输出:
['SUBDOMAIN', 'IP ADDR']
subdomain_list = []
raw_output = [["b'"], [' Performing General Enumeration of Domain: buzzfeed.com\\n[-] All nameservers failed to answer the DNSSEC query for buzzfeed.com\\n'], [' \\t SOA ns-1367.awsdns-42.org 205.251.197.87\\n'], [' \\t NS ns-1015.awsdns-62.net 205.251.195.247\\n'], [' \\t NS ns-1015.awsdns-62.net 2600:9000:5303:f700::1\\n'], [' \\t NS ns-166.awsdns-20.com 205.251.192.166\\n'], [' \\t NS ns-166.awsdns-20.com 2600:9000:5300:a600::1\\n'], [' \\t NS ns-1554.awsdns-02.co.uk 205.251.198.18\\n'], [' \\t NS ns-1554.awsdns-02.co.uk 2600:9000:5306:1200::1\\n'], [' \\t NS ns-1367.awsdns-42.org 205.251.197.87\\n'], [' \\t NS ns-1367.awsdns-42.org 2600:9000:5305:5700::1\\n'], [' \\t MX aspmx2.googlemail.com 74.125.205.27\\n'], [' \\t MX alt2.aspmx.l.google.com 74.125.68.26\\n'], [' \\t MX aspmx5.googlemail.com 74.125.195.27\\n']] #etc....
for l in raw_output:
subdomain = re.findall('[a-z0-9]+\.[a-z]+(\/[a-zA-Z0-9#]+\/?)*$', raw_output)
host = re.findall('[0-9]+(?:\.[0-9]+){3}', raw_output)
if domain and if host:
subdomain_list.append([subdomain, host])
print(subdomain_list)