Skip to content

Instantly share code, notes, and snippets.

@discarn8
Created April 4, 2023 23:02
Show Gist options
  • Save discarn8/2f1305570961c92de97cfe57d87f6be9 to your computer and use it in GitHub Desktop.
Save discarn8/2f1305570961c92de97cfe57d87f6be9 to your computer and use it in GitHub Desktop.
Use python2.7 to get the event logs from your Netgear CM600 modem in csv format
############################################################################################
# #
# GET EVENT LOGS FROM NETGEAR CM600 ROUTER/MODEM IN CSV FORMAT #
# CULMINATION OF: #
# https://stackoverflow.com/questions/20383924/how-to-access-netgear-router-web-interface #
# https://stackoverflow.com/users/1777330/murrgon #
# https://gist.github.com/DexterHaslem/d0365dd4cbbcceac22a002fa981beaae #
# #
# PYTHON 2.7 #
############################################################################################
#!/usr/bin/python2.7
import re
from csv import DictWriter
from xml.dom.minidom import parseString
import xml.dom.minidom
import urllib2
import os
hd = os.path.expanduser('~')
print hd
user = 'admin'
pwd = 'your_password'
host = '192.168.100.1'
url = 'http://' + host + '/EventLog.asp'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, host, user, pwd)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
response = opener.open(url)
stuff = response.read()
response.close()
xmlformat_regex = re.compile(r'var xmlFormat = \'([^\']*)\'')
results = xmlformat_regex.findall(stuff)
if len(results) > 0:
doc = parseString(results[0])
fn = os.path.expanduser('~') + "/CM600_EventLog.csv"
#fn = "/home/pi/CM600_EventLog.csv"
with open(fn, 'w') as out_csv:
d = DictWriter(out_csv, fieldnames=['docsDevEvIndex', 'docsDevEvFirstTime',
'docsDevEvLastTime', 'docsDevEvCounts', 'docsDevEvLevel', 'docsDevEvId', 'docsDevEvText'])
d.writeheader()
for tr in doc.documentElement.childNodes:
row = {}
for se in tr.childNodes:
v = se.childNodes[0].nodeValue
if se.localName == 'docsDevEvFirstTime' or se.localName == 'docsDevEvLastTime':
v = v.replace(',', '')
row[se.nodeName] = v
d.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment