www.pudn.com > noc.rar > chknet.py



import os, sys, string, re

f = open(sys.argv[1])

packet = []
times = []
while 1 :
    l = f.readline()
    if l == '' : break
    s = string.split(l)
    if s[2] == 'sending' :
        ax, ay = int(s[3][6:7]),int(s[3][8:9])
        d = s[4][5:]
        t= int(s[5])
        packet.append( (ax,ay,d,t) )
    elif s[1] == 'received' :
        ax, ay = int(s[0][3:4]),int(s[0][4:5])
        d = s[2]
        t = int(s[3])
        pn = 0
        while pn < len(packet):
            p = packet[pn]
            if p[2]==d and p[0]==ax and p[1]==ay :
                times.append( t - p[3] )
                break
            pn = pn+1
        if pn == len(packet) :
            print 'unexpected receive',ax,ay,d,t
        else:
            del packet[pn]

for p in packet:
    print 'lost sent (%d,%d) %s @ %d'%p
                

times.sort()
sum = reduce(lambda x, y: long(x)+long(y), times)
print '%d packets'%(len(times))
print 'min=%d, max=%d, avg=%d'%(times[0], times[-1], int(sum/len(times)))