class UDP_SNIFFER(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
while 1:
choice = raw_input("menu> ")
if choice.strip() == "":
continue
if choice.strip() == "exit":
break
if choice.strip() == "start":
print "Start to capture packets..."
self.startCapture()
continue
print "Exiting..."
def startCapture(self):
global captured_list
global start_msginx
global missing_cnt
global expected_msginx
global captured_cnt
# try to capture N packets.
start_time = time.time()
sniff(prn=pkg_callback, filter="udp and port %d" % (UDP_PORT), count=10000)
end_time = time.time()
gap = end_time - start_time
# print result
print "Sniffing is done. Result ( %d / %d ) during %f" % ( missing_cnt, captured_cnt, gap )
if __name__ == "__main__":
upr = UDP_SNIFFER()
upr.start()
upr.join()
exit(0)