我试图在Kali linux中运行console命令,但是当我将它传递给JTextPane
时输出很奇怪。当我将它显示在Netbean的输出控制台上时,它很好。
我正在尝试运行的命令:wifite -e Experiment -c 1
代码:
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);
}
}
答案 0 :(得分:2)
字符为ANSI escape codes,用于控制wifite
生成的终端输出的外观。在您的选择中,
在字符序列到达doInBackground()
的实现时,将其保留;它们都以ESC
字符开头。
检查代码并重新概述JTextPane
中的相应风格,如StyledDocument
所见here所示。
使用引用NetBeans console的here或Jansi
等库。