Netusage
A simple script to prevent surprise ISP Traffic Bills
In some backwaters of the internet, such as New Zealand, most ISPs set
strict traffic caps and charge without mercy when you exceed these
limits.
This script will save you the worry and risk of financial loss.
Features:
- To be used in cases where all traffic in a home/office network
passes through a single ethernet interface (default eth0)
- Runs once a day, and calculates your total usage in the billing
month
- You can set the billing cycle to start at any day of the month
- Program sends you a usage summary email each day (or as often as
you want), with increasingly emphatic warnings if you get close to
maxing out
Requirements
- Python 2.2.1 or later
- Your kernel configured to support the /proc filesystem
- A 'sendmail' binary on your system
Installation
Just put the script somewhere, and chmod it to ugo+x
or
Then, edit a couple of constants at the top of the script to suit your
situation.
Don't worry - it's easy, and there's nothing esoteric - I promise!
Then, add it to your crontab to run once a day (run crontab -e), and
it will send you a daily email telling you how much traffic quota you
have remaining for the month.
In your crontab script, put the (single line) entry:
0
0 * * * /path/to/netusage.py >/dev/null 2>&1
Caveats
Depending on the byte count meter on your chosen interface (see
'ifconfig'), the reports will be inaccurate up until the start of your
next billing cycle. If you want to fix this, follow these steps:
- Create a file ~/.netusage
(or the name of the file you have given at the top of the script)
- Put a single line into this file (with a newline at end):
<timeinseconds>
<rx> <tx> <rx> <tx>
where <timeinseconds>
is unix-format time (seconds since epoch) of today,
<rx>
is the total number of bytes download during the present billing cycle,
<tx>
is the total number of bytes download during the present billing cycle
Also, before you reboot or power down your gateway box, run the script
manually. This will keep the tally accurate.
Download
Download netusage.py here
Privacy Policy