title: Measure Network Data with Python
body: <p>I'm currently writing a program to shut down a computer when over a period of time (say, half an hour) network traffic is below a certain threshold.</p>
  
  <p>Here's the pseudocode that I've worked will give the correct logic:</p>
  
  <pre><code>BEGIN SUBPROGRAM
      loopFlag = True
      Wait 5 minutes    # Allows time for boot and for the machine to settle
      traffic = 0
      WHILE loopFlag = True DO
          FOR sec = 0 to 3600
              traffic += *network.traffic()*
              wait 1 second
          ENDFOR
          IF traffic &lt; trafficThreshold THEN
              loopFlag = False
          ENDIF
      ENDWHILE
      os.ShutDown()
  END SUBPROGRAM
  </code></pre>
  
  <p>What I'm looking for is the Python module or library that will allow me to measure this.</p>
  
  <p>Whilst I've <a href="https://stackoverflow.com/questions/7861586/how-to-measure-network-throughput-during-runtime">done</a> <a href="https://stackoverflow.com/questions/561999/how-can-i-monitor-limit-network-traffic-used-by-my-app">various</a> <a href="https://stackoverflow.com/questions/8148608/network-traffic-monitor-with-pcapy-in-python">research</a> into this, these don't seem to be the sort of functionality I'm after, regardless of their language.</p>
  
  <p>Any ideas on how to implement this?</p>