我有一个程序会在给定主机上启动nmap扫描,添加我拥有的参数:
def _get_all_info(self):
"""
get all the information from the scan
"""
def __add_options():
option_list = []
if self.opts is not None:
for opt in self.opts:
if opt not in lib.attacks.nmap_scan.nmap_opts:
logger.warning(set_color(
"option '{}' is not a valid nmap option "
"skipping...".format(opt)
))
else:
option_list.append(opt)
return " ".join(options_list)
scanned_data = self.NM.scan(self.ip, ports=self.ports, arguments=__add_options())
if self.pretty:
scanned_data = json.dumps(scanned_data, indent=4, sort_keys=True)
return scanned_data
我可以更轻松地编写__add_options部分吗?
答案 0 :(得分:1)
使用list comprehensions并删除无用的日志记录:
def __add_options():
return " ".join([opt for opt in self.opts if opt in lib.attacks.nmap_scan.nmap_opts])