This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

tshark with Java Application

0

Hi Everybody,

This command is used with command line correctly: C:\Program Files\Wireshark>tshark -i 1 -w "C:\workspace\runExternal\myTestCap.pcap" -T text -V > "C:\workspace\runExternal\myTestCap.txt"

But I cannot run this with my Java Application.

Can you help me how I can use this?

asked 04 Dec '12, 00:27

kilicelli's gravatar image

kilicelli
1111
accept rate: 0%

Here is the code; I want to listen my network and see the bytes like text format, and with continuousFileReader method I read the this("textCap.txt") text file...

public class ReadChangingFile {

public static void main(String args[]) throws IOException, InterruptedException{
String path = "C:/workspace/runExternal";
String execute = "C:\\Progra~1\\Wireshark\\tshark -i 1 -w C:\\workspace\\runExternal\\testCap.pcap -T text -V > C:\\workspace\\runExternal\\testCap.txt";

try { 
    Runtime.getRuntime().exec(execute); 
}catch (IOException e1) { 
    System.out.println("Error during initialization of live capture"); 
    e1.printStackTrace(); 
}

Thread.sleep(5000);     
continuousFileReader(path);

}

private static void continuousFileReader(String fileName) { String appFileName = fileName + "/testCap.txt";

File file = new File(appFileName);
if(!(file.exists())){
    System.out.println("Relevant File Does Not Exist At " +fileName+" Hence Exiting System");
    System.exit(1);
}

long lengthBefore = 0;
long length = 0;

while(true){
    RandomAccessFile reader = null;
    try {
        if ((length = file.length()) > lengthBefore) {
            try {
                reader = new RandomAccessFile(file,"r");
                reader.seek(lengthBefore);
                lengthBefore = length;
                String line = null;
                while (!((line = reader.readLine()) == null)) {
                    // do whatever with contents
                    //System.out.println(line);
                    if(line.contains("iMSI:")){
                        //System.out.println(line);

                        JOptionPane exJPane = new JOptionPane();
                        exJPane.showMessageDialog(null, line);

                        //JOptionPane.showConfirmDialog(null, line);

                    }
                }
            } catch (FileNotFoundException ex) {
                //handle exception
            }

            catch (IOException ex) {
                //handle exception
            }

        }

        Thread.sleep(10000);
    } catch (InterruptedException ex) {
        try {
            if(reader!=null){
                reader.close();
            }
        } catch (IOException ex1) {
            //handle exception
        }
    }
}

}

}

(04 Dec ‘12, 05:06) kilicelli


One Answer:

0

Please share your code which is executing the above command to analyze. you could try waitFor() function of Process process.waitFor() after executing the command.

answered 04 Dec '12, 04:15

manojdeoli's gravatar image

manojdeoli
1556
accept rate: 0%