Skip to content

Instantly share code, notes, and snippets.

@blachniet
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save blachniet/8909673 to your computer and use it in GitHub Desktop.

Select an option

Save blachniet/8909673 to your computer and use it in GitHub Desktop.
from urllib2 import urlopen
from datetime import timedelta
import re
timedelta_regex = re.compile(r'(?P<days>\d+):(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)')
def get_modem_status(modem_uri="http://192.168.100.1"):
content = urlopen(modem_uri + "/index.cgi?page=modemStatusData").read()
parts = content.split("##")
if len(parts) != 34:
raise Exception("Unexpected response from the modem.")
result = {
'ip' : parts[0],
'mac' : parts[1],
'software_version' : parts[2],
'hardware_version' : parts[3],
'status' : parts[4],
'transmitted_packets' : long(parts[5].replace(',', '')),
'transmitted_bytes' : long(parts[6].replace(',', '')),
'received_packets' : long(parts[7].replace(',', '')),
'received_bytes' : long(parts[8].replace(',', '')),
'online_time' : parts[9],
'loss_of_sync_count' : int(parts[10]),
'rx_snr' : float(parts[11]),
'rx_snr_percentage' : float(parts[12].replace('%', '')) / 100.0,
'serial_number' : parts[13],
'rx_power' : float(parts[14]),
'rx_power_percentage' : float(parts[15].replace('%', '')) / 100.0,
'cable_resistance' : float(parts[16]),
'cable_resistance_percentage' : float(parts[17].replace('%', '')) / 100.0,
'odu_telemetry_status' : parts[18],
'cable_attenuation' : float(parts[19]),
'cable_attenuation_percentage' : float(parts[20].replace('%', '')) / 100.0,
'ifl_type' : parts[21],
'part_number' : parts[22],
'status_image_uri' : parts[23],
'satellite_status_uri' : parts[24],
'unknown_25' : parts[25],
'status_html' : parts[26],
'health_html' : parts[27],
'unknown_28' : parts[28],
'unknown_29' : parts[29],
'last_page_load_duration' : parts[30],
'unknown_31' : parts[31],
'unknown_32' : parts[32] }
parts = timedelta_regex.match(result['online_time'])
if not parts:
raise Exception('Invlaid "online time" received from the modem.')
else
parts = parts.groupdict()
time_params = {}
for (name, param) in parts.iteritems():
if param:
time_params[name] = int(param)
result['online_time'] = timedelta(**time_params)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment