@@ -0,0 +1,979 @@
+#!/usr/bin/env python2%0A%0Aimport re%0Aimport subprocess as sub%0Aimport sys%0A%0ALENGTH_PAT = re.compile('%5B%5Cs%5Dlength%5B%5Cs%5D(?P%3CNUM%3E%5Cd+)')%0AWHITE_SPACE_PAT = re.compile(%22%5E(%5B%5Cs%5D+)%22)%0A%0Adef traffic_counter(port_num):%0A    length = 0%0A%0A    try:%0A        p = sub.Popen(('sudo', 'tcpdump', '-nnnx', 'port', port_num), stdout=sub.PIPE)%0A    except OSError, e:%0A        print e%0A        return%0A    except ValueError, e:%0A        print e%0A        return%0A%0A    for row in iter(p.stdout.readline, b''):%0A        row_str = row.rstrip()%0A%0A        # Prefilter%0A        if WHITE_SPACE_PAT.match(row_str):%0A            continue%0A        elif %22, length 0%22 in row_str:%0A            continue%0A%0A        match_obj = LENGTH_PAT.search(row_str)%0A        if not match_obj:%0A            continue%0A%0A        length += int(match_obj.group('NUM'))%0A        print length%0A%0A%0Adef main():%0A    if len(sys.argv) %3C 2:%0A        print %22Please input port number.%22%0A        sys.exit(0)%0A    traffic_counter(sys.argv%5B1%5D)%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add tcpdump_traffic.py