I am very new to Python and I have an existing script which is simulated to behave as an SNMP agent responding to the get requests. It does the following functionality:
This works as expected.
Now I need to enhance this script to make sure it checks the OID sent in the request and send a different response based on the OID. Any suggestions on how to do this?
It depends on what for the OIDs are in. If you have a string like 1.2.3.4
, then you can simply compare the strings directly. However, it is more useful to split the OID into a list of integers:
>>> oidstr = '1.2.3.4'
>>> oid = [int(x) for x in oidstr.split('.')]
You can compare the list equality as well.
If you have a binary string like b'\\x01\\x02\\x03\\x04'
, then you can convert it to a list of integers using a similar comprehension - oid = [x for x in oidbin]
since a binary string is iterable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.