2017-03-07 85 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中? –