python - Microsecond resolution using dpkt -


i trying create python script parse pcap file , measure traffic burstiness down sub-millisecond level. problem looks timestamps provided dpkt doesn't appear provide fine enough resolution. following script #!/usr/bin/python import dpkt, sys

f=file(sys.argv[1],"rb") pcap=dpkt.pcap.reader(f)   ts, buf in pcap:   eth=dpkt.ethernet.ethernet(buf)   size = len(eth)   print "packet size %s" % size   print "timestamp %s" % ts 

yields following results

packet size 199 timestamp 1397589057.04 packet size 119 timestamp 1397589057.04 packet size 66 timestamp 1397589057.04 packet size 247 timestamp 1397589057.04

the actual timestamps packets should have .043549 format goes down microsecond. know how full timestamp?

i assuming doing this:

for ts, buf in pcap:     print ts 

and observe timestamp 1408173480.93 instead of 1408173480.936543. because print function in python limits float 2 decimal places.

example:

>>> x = 1258494066.119061 >>> x 1258494066.119061 >>> print x 1258494066.12 

if need print full value, use format:

>>> "{0:.6f}".format(x) '1258494066.119061' 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -