我正在用Python编写一个recon工具,在尝试打印多行变量前面的字符串而不编辑字符串本身时遇到了一些问题
下面是我的代码:
# ...
query1 = commands.getoutput("ls -1 modules/recon | grep '.*\.py$' | grep -v '__init__.py'")
print("module/%s/%s" % (module_type, query1.strip(".py"))
我想添加“module/#module#u type/#module#u name”,并且module name是唯一改变的东西。因此,使用shodan和bing模块(随机)输出如下:
modules/recon/shodan
modules/recon/bing
但是我得到了
modules/recon/bing.py
shodan
谢谢!你知道吗
你可以这样做:
输出:
但是,由于您已经在从python调用unix shell,因此最好使用sed进行字符串处理:
如果要查找模块(例如modules/recon)的位置与需要输出的前缀匹配,您还可以使用shell的“globbing”功能简化命令:
另一种选择是只使用python的标准库:
相关问题 更多 >
编程相关推荐