Beispiel #1
0
  @Override
  public void nextPacket(JPacket packet, StringBuilder errbuf) {

    String source = "";
    String destination = "";
    String printResult = "";

    try {
      packet.getHeader(ipv4);
      if (!(ipv4.source()).equals(null)) {
        source = FormatUtils.ip(ipv4.source());
      }
      if (!(ipv4.destination()).equals(null)) {
        destination = FormatUtils.ip(ipv4.destination());
      }
      // textPane1.setText(textPane1.getText() + "> Source ip = " + source + ";  Destination ip = "
      // + destination + "\n");
      printResult = "> Source ip = " + source + ";  Destination ip = " + destination + "\n";
    } catch (Exception e) {
      printResult = printResult + "!!! Exception ip IP Addr > " + e.getCause() + "\n";
      textPane1.append(printResult);
      // textPane1.setCaretPosition(textPane1.getDocument().getLength());
    }

    if (packet.hasHeader(Sip.ID)) {
      packet.getHeader(sip1);
      printResult = printResult + "> sip1.getMethod().name() = " + sip1.getMethod().name() + "\n";
    }

    if (packet.hasHeader(Rtp.ID)) {
      packet.getHeader(rtp1);
      printResult =
          printResult
              + "> rtp1.csrcLength() = "
              + rtp1.csrcLength()
              + ";  rtp1.csrc() = "
              + rtp1.csrc()
              + "; rtp1.ssrc()"
              + rtp1.ssrc()
              + "\n";
    }

    /*
            if (packet.hasHeader(Tcp.ID)) {
                packet.getHeader(tcp);
                printResult = printResult + "> tcp.dst_port = " + tcp.destination() + "; tcp.src_port = " + tcp.source() + "; tcp.ack = " + tcp.ack()  + "\n";
            }
            if (packet.hasHeader(Udp.ID)) {
                packet.getHeader(udp1);
                printResult = printResult + "> udp.dst_port = " + udp1.destination() + "; udp.src_port = " + udp1.source()  + "\n";
            }
    */
    textPane1.append(printResult + "Frame " + packet.getFrameNumber() + " \n");
    // textPane1.setCaretPosition(textPane1.getDocument().getLength());
  }
 /**
  * Initialize the network packet from the pcap packet.
  *
  * @param packet The captured packet in pcap format.
  */
 private void parsePcapPacket(final PcapPacket packet) {
   this.length = packet.getTotalSize();
   this.timestamp = new Date(packet.getCaptureHeader().timestampInMillis());
   final Tcp tcp = new Tcp();
   if (packet.hasHeader(tcp)) {
     packet.getHeader(tcp);
     this.destinationPort = tcp.destination();
     this.sourcePort = tcp.source();
     this.isAck = tcp.flags_ACK();
     this.isRst = tcp.flags_RST();
     this.isSyn = tcp.flags_SYN();
   }
   final Ip4 ip = new Ip4();
   if (packet.hasHeader(ip)) {
     packet.getHeader(ip);
     this.destinationIp = FormatUtils.ip(ip.destination());
     this.sourceIp = FormatUtils.ip(ip.source());
   }
   final JBuffer storage = new JBuffer(JMemory.Type.POINTER);
   final JBuffer buffer = tcp.peerPayloadTo(storage);
   if (buffer != null) {
     this.data = buffer.getByteArray(0, buffer.size());
   }
 }
 /**
  * Creates a new fully decoded packet from the hexdump data provided.
  *
  * @param id numerical id of first protocol (DLT)
  * @param hexdump hexdump of the packet contents which will loaded into the raw data buffer
  */
 public JMemoryPacket(int id, String hexdump) {
   this(id, FormatUtils.toByteArray(hexdump));
 }
        public void nextPacket(PcapPacket pcappacket, String user) {
          if (pcappacket.hasHeader(ip)) {
            if (FormatUtils.ip(ip.source()) != FormatUtils.ip(myinet)
                && FormatUtils.ip(ip.destination()) != FormatUtils.ip(myinet)) {
              System.out.println();
              System.out.println("IP type:\t" + ip.typeEnum());
              System.out.println("IP src:\t-\t" + FormatUtils.ip(ip.source()));
              System.out.println("IP dst:\t-\t" + FormatUtils.ip(ip.destination()));
              readdata = true;
            }
          }
          if (pcappacket.hasHeader(eth) && readdata == true) {
            System.out.println("Ethernet type:\t" + eth.typeEnum());
            System.out.println("Ethernet src:\t" + FormatUtils.mac(eth.source()));
            System.out.println("Ethernet dst:\t" + FormatUtils.mac(eth.destination()));
          }
          if (pcappacket.hasHeader(tcp) && readdata == true) {
            System.out.println("TCP src port:\t" + tcp.source());
            System.out.println("TCP dst port:\t" + tcp.destination());
          } else if (pcappacket.hasHeader(udp) && readdata == true) {
            System.out.println("UDP src port:\t" + udp.source());
            System.out.println("UDP dst port:\t" + udp.destination());
          }
          /*			if (pcappacket.hasHeader(rip) &&
          readdata == true) {
          System.out.println("RIP count:\t" + rip.count());
          System.out.println("RIP header:\t" + rip.getHeader());
          } */
          if (pcappacket.hasHeader(arp) && readdata == true) {

            // System.out.println("ARP decode header:\t" + arp.decodeHeader());
            // System.out.println("ARP hardware type:\t" + arp. hardwareType());
            // System.out.println("ARP hw type descr:\t" + arp.hardwareTypeDescription());
            // System.out.println("ARP hw type enum:\t" + arp.hardwareTypeEnum());
            // System.out.println("ARP hlen:\t-\t" + arp.hlen());
            // System.out.println("ARP operation:\t-\t" + arp.operation());
            // System.out.println("ARP plen:\t-\t" + arp.plen());
            // System.out.println("ARP protocol type:\t" + arp.protocolType());
            // System.out.println("ARP prtcl type descr:\t" + arp.protocolTypeDescription());
            // System.out.println("ARP prtcl type enum:\t" + arp.protocolTypeEnum());
            // System.out.println("ARP sha:\t-\t" + FormatUtils.mac(arp.sha()));
            // System.out.println("ARP sha length:\t-\t" + arp.shaLength());
            // System.out.println("ARP spa:\t-\t" + FormatUtils.ip(arp.spa()));
            // System.out.println("ARP spa length:\t-\t" + arp.spaLength());
            // System.out.println("ARP spa offset:\t-\t" + arp.spaOffset());
            // System.out.println("ARP tha:\t-\t" + FormatUtils.mac(arp.tha()));
            // System.out.println("ARP tha length:\t-\t" + arp.thaLength());
            // System.out.println("ARP tha offset:\t-\t" + arp.thaOffset());
            // System.out.println("ARP tpa:\t-\t" + FormatUtils.ip(arp.tpa()));
            // System.out.println("ARP tpa length:\t-\t" + arp.tpaLength());
            // System.out.println("ARP tpa offset:\t-\t" + arp.tpaOffset());
            System.out.println("ARP Packet!");
            readdata = true;
          }
          if (pcappacket.hasHeader(payload) && readdata == true) {
            payloadContent = payload.getPayload();
            System.out.println("Payload:\n");
            for (int x = 0; x < payloadContent.length; x++) {
              System.out.print(payload.toHexdump());
            }
          }
          if (readdata == true) System.out.println("-\t-\t-\t-\t-");
          readdata = false;
        }