File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed
Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change 1+ # Network-Usage-Tracker
2+ A python script to keep a track of network usage and notify you if it exceeds a specified limit
3+ (only support for wifi right now)
4+
5+ ### Requirements:
6+
7+ #####** This script needs Python 3+**
8+
9+ You may also need to install vnstat if you don't have it already installed
10+ ``` bash
11+ $ sudo apt-get install vnstat
12+ ```
13+
14+ ### Usage:
15+
16+ ``` bash
17+ $ python bandwidth_py3.py xxx MiB/GiB &
18+ ```
19+ The '&' has been added to run the process in background. If you want to stop the process at any time use :
20+
21+ ``` bash
22+ $ ps -ef
23+ ```
24+ to get the list of running processes and then get the pid of the process you want to kill and do :
25+
26+ ``` bash
27+ $ sudo kill pid
28+ ```
Original file line number Diff line number Diff line change 1+ #Contributed via : https://github.com/adarshkushwah/Network-Usage-Tracker
2+
3+ import os
4+ import sys
5+ import time
6+ import threading
7+ import subprocess
8+ import tkinter
9+ import tkinter .messagebox
10+
11+
12+ def monitor (limit , unit ):
13+ check = "vnstat"
14+ proc = subprocess .Popen (check , shell = True , stdout = subprocess .PIPE )
15+ output = proc .communicate ()
16+ output = str (output )
17+ #print output
18+ l = []
19+ for t in output .split ():
20+ try :
21+ if t == "MiB" or t == "GiB" :
22+ l .append (t )
23+ else :
24+ l .append (float (t ))
25+ except ValueError :
26+ pass
27+
28+ if unit == l [5 ] and limit < l [4 ]:
29+ print ("\n network usage limit exceeded!\n " )
30+ top = tkinter .Tk ()
31+
32+ def hello ():
33+ tkinter .messagebox .showinfo ("Warning!" , "Network usage limit exceeded!!!!" )
34+ B1 = tkinter .Button (top , text = "Warning" , command = hello )
35+ B1 .pack ()
36+ top .mainloop ()
37+ arg = [limit , unit ]
38+ threading .Timer (60.0 , monitor , arg ).start ()
39+
40+
41+ def main ():
42+ if len (sys .argv ) > 3 or len (sys .argv ) < 3 :
43+ print ('command usage: python3 bandwidth_py3.py <data usage in MiB or GiB>' )
44+ print ('example: python3 bandwidth_py3.py 500 MiB' )
45+ print ('or python3 bandwidth_py3.py 2 GiB' )
46+ exit (1 )
47+ else :
48+ limit = float (sys .argv [1 ])
49+ unit = str (sys .argv [2 ])
50+ #callMonitor(limit, unit)
51+ monitor (limit , unit )
52+
53+
54+ if __name__ == "__main__" :
55+ main ()
You can’t perform that action at this time.
0 commit comments