Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
Created January 14, 2012 14:08
Show Gist options
  • Save jayrambhia/1611601 to your computer and use it in GitHub Desktop.
Save jayrambhia/1611601 to your computer and use it in GitHub Desktop.
Monitor your downloading data
import pcap, dpkt, socket
import os
import time
pc = pcap.pcap('eth0')
ports = (80, 8080, 443, 888)
def process():
t = time.time()
i = 0
mem = sport = dport = 0
try:
for ts, pkt in pc:
eth = dpkt.ethernet.Ethernet(pkt)
ip = eth.data
if ip.__class__ == dpkt.ip.IP:
ip1, ip2 = map(socket.inet_ntoa, [ip.src, ip.dst])
if ip.p == socket.IPPROTO_TCP:
I7 = ip.data
sport, dport = [I7.sport, I7.dport]
if sport in ports or dport in ports:
if len(I7.data) > 0:
if ts > t + (i*60):
str1 = "'" + str(int(mem/(1024*1024)))+' mb ' + str(i)+' min'+"'"
print str1
os.system("notify-send " + str1 )
i = i + 15
#print 'From %s to %s, length: %d' %(ip1, ip2, len(I7.data))
mem = mem + len(I7.data)
except KeyboardInterrupt:
return int(mem)
def main():
mem = process()
print float(mem/(1024*1024)), 'mb'
return
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment