2014-07-06 3 views
2

Java 용 jNetPcap 라이브러리를 사용하여 PCAP 파일 내의 ARP 패킷에 대한 정보를 얻으려고합니다. 내가 실제로 한 것은 이더넷 프레임 내의 발신지 및 목적지 주소와 발신자 MAC 및 ARP 패킷 내의 대상 MAC 주소를 읽는 것입니다.jNetPcap - PCAP 파일의 ARP 패킷 분석

지금까지 PCAP 파일을로드하고 패킷 캡처의 모든 패킷을 반복하며 실제로 ARP 프로토콜 인 패킷의 패킷 번호 (프레임 번호)를 표시 할 수있었습니다.

내가 추가 정보를 얻는 방법은 무엇입니까?

여기 내 코드는 지금까지 : 당신이 사용하는 jnetpcap 어떤 버전의

package firstjavapcaptest; 

import org.jnetpcap.Pcap; 
import org.jnetpcap.packet.PcapPacket; 
import org.jnetpcap.packet.PcapPacketHandler; 
import org.jnetpcap.protocol.lan.Ethernet; 
import org.jnetpcap.protocol.network.Arp; 
import org.jnetpcap.protocol.tcpip.Tcp; 

public class FirstJavaPcapTest { 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     // TODO code application logic here 

     final StringBuilder errbuf = new StringBuilder(); // for any error messages 
     final String file = "Z:\\test_pcap.pcap"; 
     Tcp tcp = new Tcp(); // Preallocate a TCP header 
     Arp arp = new Arp(); // Preallocate a ARP header 
     System.out.printf("Opening file for reading: %s%n", file); 

     Pcap pcap = Pcap.openOffline(file, errbuf); 
     if (pcap == null) { 
      System.err.printf("Error while opening device for capture: " + errbuf.toString()); 
      return; 
     } 

     PcapPacketHandler<String> jphArp = new PcapPacketHandler<String>() { 
      public void nextPacket(PcapPacket packet, String user) { 
       Ethernet ethh = new Ethernet(); 
       if (packet.hasHeader(arp)) { 
        System.out.println("[" + packet.getFrameNumber() + "]"); 
       } 
      } 
     }; 

     try { 
      pcap.loop(-1, jphArp, ""); 
     } finally { 
      pcap.close(); 
     } 
    } 

} 

답변

1

? 나는 1.3을 추정한다.

byte[] sha()   Sha. 
int  shaLength()  Sha length. 
byte[] spa()   Spa. 
int  spaLength()  Spa length. 
int  spaOffset()  Spa offset. 
byte[] tha()   Tha. 
int  thaLength()  Tha length. 
int  thaOffset()  Tha offset. 
byte[] tpa()   Tpa. 
int  tpaLength()  Tpa length. 
int  tpaOffset()  Tpa offset.` 
:

... 8 Sender hardware address (SHA) (first 2 bytes) 10 (next 2 bytes) 12 (last 2 bytes) 14 Sender protocol address (SPA) (first 2 bytes) 16 (last 2 bytes) 18 Target hardware address (THA) (first 2 bytes) 20 (next 2 bytes) 22 (last 2 bytes) 24 Target protocol address (TPA) (first 2 bytes) 26 (last 2 bytes)

그리고 다음은 jnetpcap의의 javadoc에서 아프 수준의 기능은 다음과 같습니다 다음 ARP 프로토콜의 오프셋 (offset)에 대한 위키 피 디아 기사에서입니다

관련 문제