السلام عليكم
لو سمحتوا عندي كود يسوي capture للTCP packet
ولكن يطلع error
Exception in thread "Thread-0" java.lang.ClassCastException: jpcap.packet.ARPPacket cannot be cast to jpcap.packet.TCPPacket
مع اني مسويه setFilter(ip and Tcp)
ولما اغير مكانها يطلع run time error
هذا الكود:
public class Capture implements Runnable{
public static void main(String[] args) {
Capture Thread=new Capture();
Thread object=new Thread(Thread);
object.start();
}
void Captur()
{
// declerations
JpcapCaptor jc_object;
JpcapWriter jw_object;
TCPPacket j_ob;
int ids,j;
Packet packet_id;
Packet packet_i;
NetworkInterface[]net_device = JpcapCaptor.getDeviceList();
try{
jc_object=
JpcapCaptor.openDevice(net_device[1], 65535, false, 200);
jw_object =
JpcapWriter.openDumpFile(jc_object,"ids_project.tcpdump");
for(ids=0;ids<10;ids++){
packet_id=jc_object.getPacket();
j_ob = (TCPPacket) packet_id; //هنا الخطأ
if(packet_id != null){
jc_object.setFilter("ip and tcp", true);
System.out.println("THE CAPTURE PACKET:");
System.out.println("..............................");
System.out.println("The Packet number :::: "+ids+" :::: ");
System.out.println("..............................");
System.out.println("Destination Port : "+j_ob.dst_port);
System.out.println("The Destination IP : "+j_ob.dst_ip);
System.out.println("Source Port : "+j_ob.src_port);
System.out.println("The Source IP : "+j_ob.src_ip);
System.out.println("Sequence Number : "+j_ob.sequence);
System.out.println("Window Size : "+j_ob.window);
System.out.println("The protocol embedded in the IP datagram : "+j_ob.protocol);
System.out.println("The IP length : "+j_ob.length);
System.out.println("The Offset : "+j_ob.offset);
System.out.println("The Flags :: ");
System.out.println("1.SYN : "+j_ob.syn);
System.out.println("2.Reset : "+j_ob.rst);
System.out.println("3.Push : "+j_ob.psh);
System.out.println("4.Urgent Pointer : "+j_ob.urg);
System.out.println("5.Acknowledgement : "+j_ob.ack);
System.out.println("6.Final : "+j_ob.fin);
jw_object.writePacket(packet_id);
}
}
jc_object.close();
jw_object.close();
}
catch (IOException e){
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
// TODO Auto-generated method stub
while(true)
{
System.out.println("Start Captur TCP Packet:");
Captur();
}
}
}
ياليت اللي يقدر يساعدني يرد في اسرع وقت
وشكرا...