이 정보가 도움이되기를 바랍니다. pyshark
과 dpkt
사이의 차이점을 발견했습니다. 나는 주 메모리에 pcap
파일 (크기 약 54MB)을 읽으려고했다. 다음은 렌더링없이 패킷의 진수 편대를 덤핑
dpkt 모듈
import dpkt
import time
filename="/opt/veeru_cap.pcap"
f = open(filename)
pcap = dpkt.pcap.Reader(f)
#print pcap[0] #<---Geting TypeError: 'Reader' object does not support indexing
print "Object-->",pcap
start=time.time()
print "The start time->",start
x=list(pcap) # Reading into Main Memory!
print "The end time->",time.time()
print "Total->",time.time()-start
print "Total Length/Total Number of Packet",len(x)
print "**********************PACKET**********************"
print x[0]
OUTPUT>
Object--> <dpkt.pcap.Reader object at 0x7f2ed1535210>
The start time-> 1497818746.66
The end time-> 1497818747.06
Total-> 0.407222986221
Total Length/Total Number of Packet 65150
**********************PACKET**********************
(1497807187.704669, '\x44\x49\x44\xfdg\xa2,\xd0ZG \x4x\x48\x00E\x00\x004E\[email protected]\[email protected]\xx6<\xxf\xxx\xgg\x33i4$\xc2\xf0\x80\x46\x0x\x4b\\\xfd\xea\xe0\xe4\xc2\xb4\xxx\x80\x10\x01l^\xf0\x00\x00\x01\x01\x0x\n\x00\x05\[email protected]\x054\xexx')
x84\x80\xx0\x01l^\xf0\xxx\x00\x01\xx1\xx8\n\x00\x05\[email protected]\x054\xe0J')
dpkt
을 발생하는 상황.
- 모든 패킷을 주 메모리로 읽어들이는 데 걸리는 시간이 매우 짧습니다. (파일의 패킷 계산이 쉽습니다!)
- 알다시피 나는
print pcap[0]
을 직접 인쇄하려고합니다. 그것은 패킷을 표시 할 수없는 객체이며, [참고이 POINT]
pyshark 모듈
** 내가 스크립트하지만 내 컴퓨터 위에서 실행
import pyshark
import time
filename="/opt/veeru_cap.pcap"
cap=pyshark.FileCapture(filename)
print "**********************PACKET**********************"
print cap[0] #<----Still able to print without converting into "List" or something
print "Object--->",type(cap)
start=time.time()
print "The start time->",start
x=list(cap) # Reading into Main Memory!
print "The end time->",time.time()
print "Total->",time.time()-start
재부팅 대답 **를 계속 응답이 없어지고 재부팅해야했습니다. 시간을 걸리는 메인 메모리에 전체 패킷을 읽기
- 패킷 편대를 표시하면 여기
- 내가
list
로 변환하지 않고 print pcap[0]
을 인쇄 할 수있어 wireshark
(check here)처럼, 정말 좋은 것입니다. 그래서 우리는 pcap
개체에서 반복을 할 수 있습니다. 하지만 len(pcap)
을 인쇄하려고하면 0
이 표시됩니다. 이 CPython Compiler, Linux Quad-Core Processor Intel i3
에서 테스트 1
로 길이를 보여주고있다 print pcap[0]
를 인쇄 한 후 내가 len(pcap)
을 할 경우 나는 최적화 할 수있는 몇 가지 방법이 있습니다, 완전히 문서화를 할 수 있습니다 확인하지 않았습니다.
어떤 패킷이 대부분의 pcap을 구성합니까? (프로토콜과 크기) –
Cython에서 Python 라이브러리를 호출하면 속도가 향상되지 않습니다. 자신이 작성한 비트 만 컴파일되고 나머지는 정확히 같은 속도로 실행됩니다. – DavidW
@KiranBandla - 패킷은 약 500b입니다. – Jshee