Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
import jpcap.*;
import jpcap.packet.Packet;
import jpcap.PacketReceiver;
import jpcap.JpcapCaptor; 
import jpcap.NetworkInterface; 
import jpcap.NetworkInterfaceAddress; 
import java.io.IOException; 
import java.util.Scanner; 
import javax.swing.JFrame;
public class PacketAnalyser {
    public static void main(String args[])throws java.io.IOException{
}

    /**
     * @param args the command line arguments
     */
    static String text="";
    public String capture(){
    	   
	try { 
		captor=JpcapCaptor.openDevice(devices[index], 65535, true, 20); 
		long[] packs = new long[20]; 
		int tcp = 0; 
		int udp = 1; 
		for(int j = 0;j<10;j++){ 
		long count1 = 0; 
		long count2 = 0; 
		captor.setFilter("tcp and ip", true); 
		for(int i=0;i<10;i++){ 
			  
		text1=text1+captor.getPacket()+"\n"; 
		if(captor.getPacket()!=null){count1++;}} 
		text1=text1+captor.dropped_packets + " packets dropped by kernel\n"; 
		text1=text1+count1+"\n"  ; 
		captor.setFilter("udp and ip", true); 
		for(int i=0;i<10;i++){ 
		text1=text1+captor.getPacket()+"\n"  ; 
		if(captor.getPacket()!=null){count2++;} 
		} 
		text1=text1+captor.dropped_packets + " packets dropped by kernel\n"; 
		text1=text1+count2+"\n"; 
		packs[tcp]=count1; 
		packs[udp]=count2; 
		tcp+=2; 
		udp+=2; 
		} 
		
	captor.close(); 
	return text1; }}
}



so while implementing and running this program i am finding error as "run:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - package jpcap.packet does not exist
at PacketAnalyser.<clinit>(PacketAnalyser.java:12)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)".... i m not getting where [is my mistake .. so plz help
Posted
Updated 13-Feb-12 21:08pm
v3

1 solution

Java
public static void main(String args[])throws java.io.IOException{

}


THAT will never work.

You should use a IDE like Eclipse or Netbeans, those will probably notify you that the lib is not there. And check if the lib including "JpcapCaptor" is listed to be included for the build.

Also please separate the application from the main. The main-function is just the entry point, please let that one call some object and fire that Object up. Java is OOP, not some script.
 
Share this answer
 
Comments
Member 9844001 18-Feb-13 10:34am    
pl,explain me how to run this in netbeans

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900