我正在为交互式shell创建一个帮助菜单,我需要它以格式化的方式输出列表,这个程序已经使用了argparse,当没有给出标志时,用户被重定向到命令脚本的行界面(终端)。我希望用户能够以格式化的方式查看帮助菜单:
TOOL_LIST = {
"-s": ["(Run a SQLi vulnerability scan on a URL)", "sqli"],
"-x": ["(Run a cross site scripting scan on a URL)", "xss"],
"-p": ["(Run a Port scan on a URL or given host)", "port"],
"-h": ["(Attempt to crack a given hash)", "crack"],
"-v": ["(Verify the algorithm used for a given hash)", "verify"],
"-d": ["(Do a dork check to verify if your dork is good)", "dork"],
"-f": ["(Find usable proxies)", "proxy"],
"-hh": ["(Produce a help menu with basic descriptions)", "help"]
}
def help_menu():
"""
Specs: Produce a help menu with basic descriptions
Usage: run menu
"""
print("Command Secondary-Command Descriptor")
primary_spacer = ""
descrip_spacer = ""
secondary_spacer = ""
for key in TOOL_LIST.iterkeys():
if len(key) == 3:
primary_spacer = " " * 2
secondary_spacer = " " * 10
descrip_spacer = " " * len(TOOL_LIST[key][1])
else:
primary_spacer = " " * 2
secondary_spacer = " " * 11
descrip_spacer = " " * len(TOOL_LIST[key][1])
print("{}{}{}{}{}{}".format(
primary_spacer, key, secondary_spacer,
TOOL_LIST[key][1], descrip_spacer, TOOL_LIST[key][0]
))
截至目前,它输出如下:
Command Secondary-Command Descriptor
-d dork (Do a dork check to verify if your dork is good)
-f proxy (Find usable proxies)
-v verify (Verify the algorithm used for a given hash)
-p port (Run a Port scan on a URL or given host)
-s sqli (Run a SQLi vulnerability scan on a URL)
-hh help (Produce a help menu with basic descriptions)
-x xss (Run a cross site scripting scan on a URL)
-h crack (Attempt to crack a given hash)
如何告诉python格式化菜单的输出,看起来像这样:
Command Secondary-Command Descriptor
-d dork (Do a dork check to verify if your dork is good)
-f proxy (Find usable proxies)
-v verify (Verify the algorithm used for a given hash)
-p port (Run a Port scan on a URL or given host)
-s sqli (Run a SQLi vulnerability scan on a URL)
-hh help (Produce a help menu with basic descriptions)
-x xss (Run a cross site scripting scan on a URL)
-h crack (Attempt to crack a given hash)
答案 0 :(得分:1)
这可以胜任 -
将您的descript_spacer
(在两个地方)替换为:
descrip_spacer = " " * (13 - len(TOOL_LIST[key][1]))
我选择了13,因为它看起来与你想要的完全一样。你可能想把它变成一个顶级变量。
输出 -
Command Secondary-Command Descriptor
-d dork (Do a dork check to verify if your dork is good)
-f proxy (Find usable proxies)
-v verify (Verify the algorithm used for a given hash)
-p port (Run a Port scan on a URL or given host)
-s sqli (Run a SQLi vulnerability scan on a URL)
-hh help (Produce a help menu with basic descriptions)
-x xss (Run a cross site scripting scan on a URL)
-h crack (Attempt to crack a given hash)