try:
    for pktlen, data, timestamp in p:
        print('[%s] Got data: %s' % (time.strftime('%H:%M', time.localtime(
            timestamp)), data))
except KeyboardInterrupt:
    print('%s' % sys.exc_info()[0])
print('shutting down')
print('%d packets received, %d packets dropped %d packets dropped by interface' % p.stats(
    ))
Packet sniffing in Python (Windows)