2017-02-27 18 views
0

私は、対話型シェルのヘルプメニューを作成していますが、これはフォーマット済みの方法でリストを出力するためのものです。このプログラムはすでにargparseを使用しています。スクリプト(ターミナル)のコマンドラインインターフェイスにリダイレクトされます。スペースでヘルプメニューを書式設定する

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を伝えることができます:それは、このように出力し、今の時点で

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) 
+1

あなたは(少なくとも、ように見える)なぜ私が聞いてもは、車輪の再発明していますか? 'argparse'を使います。フォーマット済みのヘルプメニューを無料で入手できます。 – DeepSpace

+0

@DeepSpaceこれは、スクリプト内のインタラクティブシェルのためのものです。ユーザーがフラグを渡すことができない場合、プログラムはシェルのコマンドをシェルから実行することができます。 (メタスプロイトの仕組みと同じように) – secxit

+0

@ hashcode55私はすでに男性でした – secxit

答えて

1

- あなたを交換し

を(両方の場所で)持つ:

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) 
+0

すごく、どうしてそれはいつもすべてのために13作品のように見えますか?笑、ありがとう! – secxit

+0

@secxitええと人々は13が不運だと言うと、そこで何をしたかを見てください。 – hashcode55