Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable SNMP on Canopy device
#!/usr/bin/python
# Set SNMP accessibility on Canopy device
# 2012 Jon Auer <jda@coldshore.com>
import sys
import urllib, urllib2
def enablewrite(dev):
# get first page
first = urllib2.urlopen(url="http://%s" % dev).read()
# extract mac
mac = None
for l in first.split():
if "URL=" in l:
l = l.replace("'", '')
mac = l.split('=')[2]
if not mac:
raise Exception('Could not find MAC address')
# do change
payload = urllib.urlencode({
'1092:SNMPReadOnly': 0,
'ok': 'Save Changes',
'mac_esn': mac,
'catindex': 1,
'pageindex': 6})
post = urllib2.urlopen(url="http://%s/himom.cgi" % (dev), data=payload).read()
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: %s DEVADDR" % (sys.argv[0])
sys.exit(1)
if enablewrite(sys.argv[1]):
sys.exit(0)
else:
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment