├── README.md ├── LICENSE └── bandwidth.py /README.md: -------------------------------------------------------------------------------- 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 2+** 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.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 | ``` 29 | To do: 30 | 1. add support for ethernet network usage 31 | 32 | Feel free to Pull requests! 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Aditya Sharma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bandwidth.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import time 6 | #import re 7 | import threading 8 | import subprocess 9 | import Tkinter 10 | import tkMessageBox 11 | 12 | def monitor(limit, unit): 13 | check="vnstat" 14 | #os.system(check) 15 | proc=subprocess.Popen(check, shell=True, stdout=subprocess.PIPE) 16 | output=proc.communicate() 17 | output=str(output) 18 | #print output 19 | l = [] 20 | for t in output.split(): 21 | try: 22 | if t=="MiB" or t=="GiB": 23 | l.append(t) 24 | else: 25 | l.append(float(t)) 26 | except ValueError: 27 | pass 28 | #print l 29 | if unit==l[5] and limit3 or len(sys.argv)<3: 46 | print 'command usage: python bandwidth.py ' 47 | print 'example: python bandwidth.py 500 MiB' 48 | print 'or python bandwidth.py 2 GiB' 49 | exit(1) 50 | else: 51 | limit=float(sys.argv[1]) 52 | unit=str(sys.argv[2]) 53 | #callMonitor(limit, unit) 54 | monitor(limit, unit) 55 | 56 | if __name__ == '__main__': 57 | main() 58 | --------------------------------------------------------------------------------