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

Piping output from tshark to Java program

0

Lets say that the tshark command for piping the output from tshark is :

tshark -i your_interface -n | your_program

I would like to pipe the output from tshark to the java program.

I compiled the java file and i piped the tshark output to the java program like this :

tshark -i 1 -n | java "C:\Users\L33604\Desktop\Eclipse Indigo x64-Bit\eclipse\project workspace\Splunk Project\src\Program.class"

The error was thrown :

could not find or load main class : C:\\..... tshark an error occurred while printing packets : invalid arguement.

The question is what is the way to pipe the tshark output to the java program using tshark command?

asked 01 May '12, 18:13

misteryuku's gravatar image

misteryuku
20242630
accept rate: 0%

edited 01 May '12, 23:57

grahamb's gravatar image

grahamb ♦
19.8k330206


2 Answers:

0

"could not find or load main class" is a Java error; there's something wrong with your program or with the way you're running it with the "java" command. I can't help you with that.

"an error occurred while printing packets : invalid argument" may just be an error given when TShark tries to write to a pipe when the program on the other side of the pipe has terminated.

answered 01 May '12, 19:17

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196
accept rate: 19%

0

---- "could not find or load main class"

As already mentioned, there is something wrong with your java class file, most certainly the main method is missing in your class file. I think you will get more detailed information in a Java forum.

Here is a working example:

Echo.java

import java.io.*;

public class Echo { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = in.readLine()) != null && s.length() != 0) System.out.println(s); // An empty line or Ctrl-Z terminates the program } } ///:~

Compile it: javac Echo.java

Run it: tshark -i 1 -n | java Echo

Note: just 'java Echo' not 'java Echo.class', as it would expect a main method then!

Output:

Capturing on VMware Accelerated AMD PCNet Adapter (Microsoft's Packet Scheduler)
0.000000 192.168.30.142 -> 192.168.30.2 ICMP 74 Echo (ping) request id=0x0200, seq=15106/571, ttl=128
0.000116 192.168.30.2 -> 192.168.30.142 ICMP 74 Echo (ping) reply id=0x0200, seq=15106/571, ttl=128

Hint: This is buffered input stream reading, so it take some time until the code prints something on the CLI (the buffer needs to be filled first).

---- "tshark an error occurred while printing packets : invalid arguement"

I have no idea where that comes from. Does this work without errors on your system: tshark -i 1 -n

Regards
Kurt

answered 01 May '12, 21:56

Kurt%20Knochner's gravatar image

Kurt Knochner ♦
24.8k1039237
accept rate: 15%