2014-04-15

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

#!/usr/bin/env 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)
  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_bytesmatch_data['remaining'].to_f )

#get the sleepytime gigs remaining
match_data text.match(/(?<remaining>[0-9\.]*) GB<br>Remain</)
remaining_bonus_bytes gigabyte_to_bytesmatch_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
next_reset_date.year
next_reset_date.month
#what month was previous?
-=1
12 if == 0
next_reset_date.day
next_reset_date.hour
next_reset_date.min
reset_date Time.localymdhM)

#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" % [dayshoursminutes]
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

Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
2 plus 3
Answer:
required
subscribe
 
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008