def readconf(host, community): """Read configuration data from Airport. Rop writes: Reading from flash Reading is done by issuing SNMP get-requests for 1.3.6.1.4.1.762.2.2.1.1.n. This request will then return a string containing a 256 byte block having offset (n - 1) * 256. Example: to read the configuration block, one would issue SNMP get-requests for 1.3.6.1.4.1.762.2.2.1.1.1 through 1.3.6.1.4.1.762.2.2.1.1.68. """ s = session.session(host, community) data = "" # We could be faster if we dont wait for each response before # sending the next one. The apple tool does so. for i in range(1, 69): encoded_objid = s.encode_oid([1, 3, 6, 1, 4, 1, 762, 2, 2, 1, 1, i]) question = s.encode_request("GETREQUEST", [encoded_objid], []) answer = s.send_and_receive(question) (encoded_objids, encoded_values) = s.decode_response(answer) values = map(s.decode_value, encoded_values) data += values[0] s.close() del (s) return data
def writeconf(host, community, data): """Write configuration Data to an Airport. Rop writes: Writing to flash Writing to flash is done by writing to 1.3.6.1.4.1.762.2.3.1.1.n, writing the 256 bytes starting at position (n - 1) * 256. The write is not actually done until the entire block to be written is received, and the length of the block is written as an integer to 1.3.6.1.4.1.762.2.1.2.0 and 1.3.6.1.4.1.762.2.1.3.0. The unit then checks a checksum in the data, encoded as two bytes directly after the last byte. This checksum is the lowest 16 bits of the sum of all the bytes to be written, LSB first. If the checksum matches, the appropriate part of the flash is overwritten with the new data, and the unit reboots. Both flash-reads and writes need to be done with the read/write community. An attempt to read them with 'public' fails on a 'no such name' error. """ s = session.session(host, community) for i in range(0, 68): encoded_objid = s.encode_oid([1, 3, 6, 1, 4, 1, 762, 2, 3, 1, 1, i + 1]) encoded_value = s.encode_string(data[i * 256 : (i + 1) * 256]) question = s.encode_request("SETREQUEST", [encoded_objid], [encoded_value]) answer = s.send_and_receive(question) # we don't need this - do we? (encoded_objids, encoded_values) = s.decode_response(answer) objids = map(s.decode_value, encoded_objids) values = map(s.decode_value, encoded_values) # "writing to flash" encoded_objid = s.encode_oid([1, 3, 6, 1, 4, 1, 762, 2, 1, 2, 0]) encoded_value = s.encode_integer(17336) question = s.encode_request("SETREQUEST", [encoded_objid], [encoded_value]) answer = s.send_and_receive(question) # unneeded (encoded_objids, encoded_values) = s.decode_response(answer) objids = map(s.decode_value, encoded_objids) values = map(s.decode_value, encoded_values) encoded_objid = s.encode_oid([1, 3, 6, 1, 4, 1, 762, 2, 1, 3, 0]) encoded_value = s.encode_integer(17336) question = s.encode_request("SETREQUEST", [encoded_objid], [encoded_value]) answer = s.send_and_receive(question) # unneeded (encoded_objids, encoded_values) = s.decode_response(answer) objids = map(s.decode_value, encoded_objids) values = map(s.decode_value, encoded_values)