안녕 얘들 아, 어떻게 pcap 파일의 각 패킷에 대한 패킷 길이를 수집 할 수 있습니까? 고마워요pcap 파일의 패킷 길이를 수집
1
A
답변
7
필자는 문서를 읽는 하이테크 방법을 제안합니다. C에서
caplen a bpf_u_int32 giving the number of bytes of the packet that are available from the capture len a bpf_u_int32 giving the length of the packet, in bytes (which might be more than the number of bytes available from the cap- ture, if the length of the packet is larger than the maximum num- ber of bytes to capture)
예 :
/* Grab a packet */ packet = pcap_next(handle, &header); if (packet == NULL) { /* End of file */ break; } printf ("Got a packet with length of [%d] \n", header.len);
pcapy library 파이썬의 또 다른 하나
import pcapy reader = pcapy.open_offline("packets.pcap") while True: try: (header, payload) = reader.next() print "Got a packet of length %d" % header.getlen() except pcapy.PcapError: break
0
남자 PCAP 사용할 수 실제로 두 개의 서로 다른 길이가 우리에게 아래의 두 예제는 잘 작동합니다.
파이썬을 사용하여 C,은 WinPcap- , SCAPY
(은 WinPcap) (컴파일러 CL, 마이크로 소프트 VC) 를 하고 그것을 잘 작동합니다 . 컴파일러 전처리
u_int getpkt_size(char * pcapfile){
pcap_t *indesc;
char errbuf[PCAP_ERRBUF_SIZE];
char source[PCAP_BUF_SIZE];
u_int res;
struct pcap_pkthdr *pktheader;
u_char *pktdata;
u_int pktsize=0;
/* Create the source string according to the new WinPcap syntax */
if (pcap_createsrcstr(source, // variable that will keep the source string
PCAP_SRC_FILE, // we want to open a file
NULL, // remote host
NULL, // port on the remote host
pcapfile, // name of the file we want to open
errbuf // error buffer
) != 0)
{
fprintf(stderr,"\nError creating a source string\n");
return 0;
}
/* Open the capture file */
if ((indesc= pcap_open(source, 65536, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf)) == NULL)
{
fprintf(stderr,"\nUnable to open the file %s.\n", source);
return 0;
}
/* get the first packet*/
res=pcap_next_ex(indesc, &pktheader, &pktdata);
if (res !=1){
printf("\nError Reading PCAP File");
return 0;
}
/* Get the packet size*/
pktsize=pktheader->len;
/* Close the input file */
pcap_close(indesc);
return pktsize;
}
멋진 SCAPY
from scapy.all import *
pkts=rdpcap("data.pcap",1) # reading only 1 packet from the file
OnePkt=pkts[0]
print len(OnePkt) # prints the length of the packet
+0
왜 거기에 ntohs가 없습니까 (pktheader-> len)? –
관련 문제
- 1. pcap 왜 항상 8 바이트 패킷 ... 왜?
- 2. pcap 라이브러리를 사용하여 패킷 스니핑을 돕는다
- 3. pcap 함수 : pcap_open() 질문
- 4. PCap 라이브러리 문제 수신
- 5. libapcap을 사용하여 pcap 파일을 구문 분석하는 방법.
- 6. PCap 성능
- 7. PCAP 대안
- 8. Perl에서 MP3 파일의 길이를 얻는 방법은 무엇입니까?
- 9. C#에서 사운드 파일의 길이를 가져옵니다
- 10. MATLAB에서 파일의 길이를 얻는 방법은 무엇입니까?
- 11. 오디오 파일의 길이를 결정하는 방법이 있습니까
- 12. 오디오 파일의 길이를 찾는 방법 (초 단위)
- 13. AVAudioPlayer와 관련된 오디오 파일의 길이를 결정하는 방법
- 14. pcap 유닉스 버퍼링은 어떻게 작동합니까?
- 15. pcap 파이썬 라이브러리?
- 16. 스레딩 및 pcap 문제
- 17. 누구나 * .pcap 조작 라이브러리에 대한 경험이 있습니까?
- 18. 패킷 페이로드를 삭제하는 도구는 무엇입니까?
- 19. libpcap 패킷 크기
- 20. PCAP 웹 서비스 사용 로깅 인 경우
- 21. C# 용 Pcap을 사용한 패킷 로깅
- 22. 어떤 패킷 캡처 형식이 더 좋습니까?
- 23. Perl 네트워크 프레임/패킷 파서
- 24. PCAP 파일을 시간 이동시키는 도구입니까?
- 25. libpcap setfilter() 함수와 패킷 손실
- 26. 패킷 데이터 구조?
- 27. TCP 패킷 끝을 어떻게 표시해야합니까?
- 28. FFMPEG를 사용하여 업로드 한 후 오디오 파일의 길이를 얻는 방법
- 29. Rails에서 seed.rb 파일의 문자열 열 길이를 제한 할 수 있습니까?
- 30. VB.net에서 mp3 파일의 길이를 (밀리 초 단위로) 결정하십시오.
프로그래밍 언어 설정을 사용하여 파이썬에서 또 다른 wroking 예에서 pcap.h 및 설정 HAVE_REMOTE을 포함하는 것을 잊지 마세요? – brickner
-1 질문에 대한 답변을 제공하지 않습니다. – bortzmeyer