跟踪IP地址

时间:2012-07-26 13:27:04

标签: java network-programming ip ip-address jpcap

我想跟踪IP地址,其中有135个目标端口,然后在具有相同IP地址的下一个数据包中有4445个目标端口。 我尝试下面的代码,但无法运行它。 怎么解决?

           packet = jpcap.getPacket();
           if(packet instanceof IPPacket){
           IPPacket ipp = (IPPacket)packet;
           InetAddress destAdd = ipp.dst_ip;
           InetAddress srcAdd = ipp.src_ip;
           if(ipp instanceof TCPPacket){
           TCPPacket tcp = (TCPPacket)ipp;
            int destPort = tcp.dst_port;
            int srcPort = tcp.src_port;
            if(destPort == 135)
            {

                System.out.println(srcAdd + " " + destAdd + " " +srcPort + " "  + destPort);
                Packet packet2 = jpcap.getPacket();
                if(packet2 instanceof IPPacket){
                    IPPacket ipp2 = (IPPacket)packet2;
                    InetAddress destAdd2 =ipp2.dst_ip;
                    InetAddress srcAdd2 = ipp.src_ip;
                    if(destAdd2 == destAdd && srcAdd2 == srcAdd ){
                    if(ipp2 instanceof TCPPacket){
                        TCPPacket tcp2 =(TCPPacket)ipp2;
                        int destPort2 = tcp2.dst_port;
                        int srcPort2 = tcp2.src_port;
                        if(destPort2 == 4444){

                        System.out.println(srcAdd2 + " " + destAdd2 + " " +srcPort2 + " "  + destPort2);    
                        }
                     }       
                    }
                }
            }
           }

0 个答案:

没有答案