【发布时间】:2020-09-01 11:37:19
【问题描述】:
我有一个需要在 python 中运行并获取输出的进程。如何运行它,以便用户可以指定可以在进程上运行的可选参数。到目前为止,这就是我的函数的样子。
async def analyze_target(self, target, batchSize, delay, maxdepth, maxurls, maxwait, recursive, useragent, htmlmaxcols, htmlmaxrows):
cmd = "wappalyzer"
if batchSize != "":
cmd = cmd + " --batch-size=" + batchSize
if delay != "":
cmd = cmd + " --delay=" + delay
if maxdepth != "":
cmd = cmd + " --max-depth=" + maxdepth
if maxurls != "":
cmd = cmd + " --max-urls=" + maxurls
if maxwait != "":
cmd = cmd + " --max-wait=" + maxwait
if recursive == True:
cmd = cmd + " --recursive"
if useragent != "":
cmd = cmd + " --user-agent=" + useragent
if htmlmaxcols != "":
cmd = cmd + " --html-max-cols=" + htmlmaxcols
if htmlmaxrows != "":
cmd = cmd + " --html-max-rows=" + htmlmaxrows
cmd = cmd + " " + target
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
tmp = p.stdout.read()
self.logger.info(tmp)
p_status = p.wait()
"""
Returns log of what was wappalyzed
"""
message = f"target {target} has been wappalyzed with output {tmp}"
# This logs to the docker logs
self.logger.info(message)
return tmp
【问题讨论】: