2017-03-07 84 views
0

我試圖在Kali linux中運行控制檯命令,但輸出只是奇怪,當我管它到JTextPane。當我把它放在Netbean的輸出控制檯上時,它很好。JTextPane輸出奇怪的控制檯字符

命令,我試圖運行:wifite -e Experiment -c 1

enter image description here

代碼:

public cracker(JTextPane aOutputPane) 
     { 
     super(); 
     mOutputPane = aOutputPane; 
    } 
    @Override 
    protected String doInBackground() throws Exception 
    { 
    Process p = null; 
    try 
    { 
     String Channel=CNinput.getText(); 
     String WName=WN.getText(); 
     p = Runtime.getRuntime().exec("wifite -e "+WName+" -c "+Channel); 
    } 
    catch (IOException ex) 
    { 
     Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex); 
    } 
    BufferedReader buf = new BufferedReader(new InputStreamReader(p.getInputStream())); 
    String line = ""; 
    String output = ""; 
    try 
    { 
     while ((line = buf.readLine()) != null) 
     { 
     publish(line); 
     output += line + "\n"; 
     } 
    } 
    cat 

ch (IOException ex) 
    { 
     Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex); 
    } 
    try 
    { 
     p.waitFor(); 
    } 
    catch (InterruptedException ex) 
    { 
     Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex); 
    } 
    return output; 
    } 
    @Override 
    protected void process(java.util.List<String> aChunks) 
    { 
    mOutputPane.setText(null); 
    final String intermediateOutput = aChunks.stream().collect(Collectors.joining("\n")); 
    final String existingText = mOutputPane.getText(); 
    final String newText = existingText + "\n" + intermediateOutput; 
    mOutputPane.setText(newText); 

    } 

} 

回答

2

的字符爲ANSI escape codes,旨在控制由wifite產生的終端輸出的外觀。在您的選項中,

  • 確保字符序列到達doInBackground()時的字符序列;他們都以ESC這個字符開頭。

  • 檢查代碼並重述JTextPane中的相應樣式,如StyledDocument看到的here所示。

  • 使用庫如NetBeans consoleJansi,引用here

+0

經過一些與你提到的東西混合使用後,我發現它很有用,特別是Jansi,是否可以實現它到.setText以及如何?我只能在system.out上找到對AnsiConsole.systemInstall();的有限引用。 –

+0

我不確定'Jansi'直接支持這種用法,但它可能值得看看它如何解析。在這種情況下,我從來不需要超過一些'SimpleAttributeSet'實例。 – trashgod

+0

我如何使用JTextpanel使用SimpleAttributeSet,這意味着我將如何允許控制檯管道輸出將管道格式化文本導入到jtextpanel中? –