1 #!/usr/bin/python
 2 import base64
 3 import httplib
 4 import re
 5 
 6 username, password = 'foo', 'bar'
 7 
 8 IP = '137.112.255.80'
 9 
10 def die(text):
11 	print text
12 	exit(1)
13 
14 s = httplib.HTTPSConnection(IP, 443)
15 try:
16 	s.request('GET', 'https://www.rose-hulman.edu/TSC/tools/network_usage_tool/', None, {'Authorization': "Basic %s" % base64.b64encode("%s:%s" % (username, password))})
17 except:
18 	die("No network connection")
19 
20 response = s.getresponse()
21 
22 if response.status == 200 or response.status == 302: pass
23 elif response.status == 401: die("Kerberos error: bad authentication")
24 elif response.status == 404: die("Unable to find TSC bandwidth page: bad page request")
25 else: die("HTTP error %d" % response.status)
26 
27 html = response.read()
28 
29 if 'a limit has been placed on the frequency that users may access this tool' in html: die("Rate limit tripped")
30 
31 matches = re.findall("<span class='(?:valid|warning|invalid)'>(.*?)</span>", html)
32 values = dict(zip(['1D', '1D%', '1U', '1U%', '3D', '3D%', '3U', '3U%'], map(lambda x: float(x.replace('%', '').replace(' MB', '')), matches)))
33 
34 for k in sorted(values.keys()): print "%s:\t%d" % (k, int(round(values[k])))