| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 
 |  
import java.net.InetAddress;
 
import jpcap.packet.Packet;
import jess.*;
import  jpcap.packet.*;
public class Filter_TCP_Pkt {
 
	Packet packet;
	TCPPacket tcpPacket;
 
	Console console = new Console();
	private String dataPacket;
 
	public void filter_tcp_pkt(){
 
		Capture capture = new Capture();
	try{
		if (packet instanceof TCPPacket) {
	        tcpPacket = (TCPPacket) packet;
	        byte[] data = tcpPacket.data;
 
	        dataPacket = new String(data, "ISO-8859-1");
 
	        console.print("\t Adr IP Source: "+
    		  " (" + "<"+tcpPacket.src_ip+">" + 
    		  ")Adr IP Distination:"+"<"+tcpPacket.dst_ip+">"+"\n" );
 
           console.print("\t[Paquet TCP] - Port source : " +
                  String.valueOf(tcpPacket.src_port) +
                  " (" + //tcpPacket +
                  ") Destination port : " +
                  String.valueOf(tcpPacket.dst_port) +
                  " (" + //tcpPacket.dst_ip +
                  ")\n\tSequence Number : " +
                  String.valueOf(tcpPacket.sequence) +
                  "\n\tAcknowledgment Number : " +
                  String.valueOf(tcpPacket.ack_num) +
                  "\n\tHeader Length : " +
                  String.valueOf(tcpPacket.header.length));
                  // Flags
                  if (tcpPacket.urg)
                    console.println("\n\tURG[0x" + Integer.toHexString(tcpPacket.urgent_pointer) + "]");
                  if (tcpPacket.ack)
                    console.println("\n\tACK[0x" + Long.toHexString(tcpPacket.ack_num) + "]");
                  if (tcpPacket.psh)
                    console.println("\n\tPSH");
                  if (tcpPacket.rst)
                    console.println("\n\tRST");
                  if (tcpPacket.syn)
                    console.println("\n\tSYN[0x" + Long.toHexString(tcpPacket.sec) + "]");
                  if (tcpPacket.fin)
                    console.println("\n\tFIN");
                  console.println("\tData : " + dataPacket);
 
 
		}
  console.println("");
}catch (Exception e) {
  e.printStackTrace();
}
 
  }
// lexecution du fichier jess qui contient les règles de filtrage
	try{	
		  Rete rete = new Rete();
		  rete.store("tcpPacket",TcpPacket);
		  rete.executeCommand("(batch C:/Users/Hacene/Desktop/Projet_Fin_Etu/Analyser_tcp_pkt.clp)");
		  rete.executeCommand("(reset)");
		  rete.executeCommand("(run)");
	}
	catch(JessException jess){
		jess.printStackTrace();
	}	
} | 
Partager