Let me tell you about my internet service provider. Because of my location, my only options for "hightspeed" internet is HughesNet, a satellite based internet service provider. The price is high, the service is lackluster, the speed is low, and the monthly data cap is wretched. I have a 5 Gigabyte monthly allowance that can be used from 8AM til 2AM and another 5 Gigabyte allowance that can be used from 2AM - 8AM. Yea, most mobile phone data plans are just as good.
Oh yea, and that data allowance includes both download data and upload data.
As soon as my monthly allowance is consumed, my network is throttled down to dialup speed, which makes using the contemporary internet quite problematic.
Since I didn't want to have to endure that crap, I needed a way to decently keep track of my data usage. Unfortunately, all of the resources provided by HughesNet for tracking data usage are lousy and don't meet my needs as a user of their service. Fortunately HughesNet's modem provides some semi-accurate data that I can parse and display in a way of my choosing.
So with my trusty text editor in hand, I used a bit of Ruby to scrap data from the modem and make a rough projection to determine if the data usage rate so far this month will result in running out of data.
NOTE: this script was updated on 2014-05-07 and is available at http://hoof.jezra.net/snip/ol Enter the Ruby
#------------------------------------
# What is Your Data Cap in Gigabytes?
#-------------------------------------
data_cap_in_gigabytes = 5
#we will need to open a url
require 'open-uri'
#convert a gigabyte number to bytes
def gigabyte_to_bytes(i)
i * 1000000000 #that is how they determine a Gig
end
#what is the total allowance in bytes?
ALLOWANCE = gigabyte_to_bytes(data_cap_in_gigabytes)
#what is the URL we need to scrape?
URL = "http://192.168.0.1/cgi-bin/index.cgi?Command=11"
#read the text from the URL
text = open(URL).read()
####use some sloppy regex to get important data
#get the gigs remaining
match_data = text.match(/(?<remaining>[0-9\.]*) GB<br>Remain </)
remaining_bytes = gigabyte_to_bytes( match_data['remaining'].to_f )
#get the sleepytime gigs remaining
match_data = text.match(/(?<remaining>[0-9\.]*) GB<br>Remain</)
remaining_bonus_bytes = gigabyte_to_bytes( match_data['remaining'].to_f )
#find the date of the next reset
match_data = text.match(/Resets in (?<days>[0-9]*) days, (?<hours>[0-9]*) hr and (?<min>[0-9]*) min/)
offset = match_data['days'].to_i*86400 + match_data['hours'].to_i*3600 + match_data['min'].to_i*60
NOW = Time.now()
next_reset_date = NOW + offset
#when was the reset date? A month before the next reset date
y = next_reset_date.year
m = next_reset_date.month
#what month was previous?
m -=1
m = 12 if m == 0
d = next_reset_date.day
h = next_reset_date.hour
M = next_reset_date.min
reset_date = Time.local( y, m, d, h, M)
#how much time has elapsed?
elapsed_time = NOW - reset_date
#how fast is the data being used?
used_data = ALLOWANCE - remaining_bytes
data_per_second = used_data / elapsed_time
#how many seconds will it take to use the remaining data?
seconds_to_use_remaining_data = remaining_bytes / data_per_second
#when will the shitty throttling occur?
throttle_date = NOW+seconds_to_use_remaining_data
puts "---- Projected Throttling ----"
puts "Next Reset Date: #{next_reset_date}"
puts "Throttling Date: #{throttle_date}"
#what is the difference in seconds?
difference_in_seconds = next_reset_date - throttle_date
#is the throttle date before the next reset?
throttled = next_reset_date > throttle_date
seconds = difference_in_seconds.abs
#convert the difference is seconds to days, hours, minutes, seconds
days = (seconds / 86400).to_i
seconds -= days * 86400
hours = (seconds / 3600).to_i
seconds -= hours * 3600
minutes = (seconds / 60).to_i
seconds -= minutes * 60
#print the difference in d h m format
if throttled
puts "Projected throttling in %d days, %d hours, %d Minutes" % [days, hours, minutes]
else
puts "Throttling is not project at this time"
end
puts ""
For easier copy/paste the script is also available at http://hoof.jezra.net/snip/oj.
This script was written to use the less-than-decent html output of the t1100 HughesNet modem and may or may not work on other modems. Your mileage may vary.
Now quit reading, and go solve a problem that needs solving.
NOTE: this script was updated on 2014-05-07 and is available at http://hoof.jezra.net/snip/ol