delimitry / snmp-server Goto Github PK
View Code? Open in Web Editor NEWSNMP server in pure Python
License: MIT License
SNMP server in pure Python
License: MIT License
Hello. I´m in a project where I'm trying to use your server. Right now I'm doing tests to the server with JMeter. I´m using the intraway SNMP plugin for JMeter and I can make snmpgets but not snmpwalks. JMeter said to me that it´s an exception using the get command. Maybe I have to start the server with any parameter or I don´t know. I used to start it in debug option and with a config.py file. Thanks in advance. hope to write me soon.
snmpset -v2c -c public 0.0.0.0:161 .1.3.6.1.4.1.1.3.0 s "new value"
I noticed that the example use is passing in 'public' as the community string.
Is it possible to set it to a custom string?
Support config file for programming the responses.
May be, it is required to support OID wildcards 🤔
For example:
{
"*": lambda oid: str(oid), # to return OID string value as a response to every request
}
Or:
{
"OID1": "string",
"OID2": 12345,
"OID3": Timeticks(123456000),
"OID3": random.randint(1, 10),
}
This requires ability to write values for ASN.1 types.
Hi
Certain OIDs only support a range of values (IF-MIB::ifAdminStatus) / enumeration, and when trying to set
them with a value outside the supported values, it should fail with wrongValue
.
Is it possible to add support for this?
Looks like after the last bugfix the snmpwalk stopped working:
running snmpwalk -v 2c -c public 0.0.0.0:161 .1.3.6.1.4.1
crashes the server
SNMP server listening on 0.0.0.0:161
Traceback (most recent call last):
File "./snmp-server.py", line 920, in <module>
main()
File "./snmp-server.py", line 914, in main
snmp_server(host, port, oids)
File "./snmp-server.py", line 854, in snmp_server
error_status, error_index, oid, oid_value = handle_get_next_request(oids, oid)
UnboundLocalError: local variable 'oid' referenced before assignment
Sample Request: snmpget -v 2c -c public 10.16.178.241 1.3.6.1.2.1.1.2.0 1.3.6.1.2.1.1.3.0
Responds only with value for first OID
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.9.1.123
[root@centos ~]#
config_file:
# SNMP server response config example
def my_response(oid):
res = '|'.join(oid.split('.'))
return octet_string('response: {}'.format(res))
DATA = {
'1.3.6.1.4.1.1.1.0': integer(12345),
'1.3.6.1.4.1.1.2.0': bit_string('\x12\x34\x56\x78'),
'1.3.6.1.4.1.1.3.0': octet_string('test'),
'1.3.6.1.4.1.1.4.0': null(),
'1.3.6.1.4.1.1.5.0': object_identifier('1.3.6.7.8.9'),
'1.3.6.1.4.1.1.6.0': real(1.2345),
'1.3.6.1.4.1.1.7.0': double(12345.2345),
# notice the wildcards in the next OIDs:
'1.3.6.1.4.1.1.?.0': lambda oid: octet_string('? {}'.format(oid)),
'1.3.6.1.4.1.2.*': lambda oid: octet_string('* {}'.format(oid)),
# lambda or function, with single oid argument, can be used for response generation
'1.3.6.1.4.1.1001.1.0': my_response,
'1.3.6.1.4.1.1002.1.0': lambda oid: octet_string('-'.join(oid.split('.'))),
'1.3.6.1.2.1.1.2.0': object_identifier('1.3.6.1.4.1.9.1.123'),
'1.3.6.1.2.1.1.3.0': timeticks(2093505391),
}
Here is the debug output:
[DEBUG] Received 57 bytes from ('198.18.134.29', 35359)
[DEBUG] ASN1_SEQUENCE: length = 55
[DEBUG] ASN1_INTEGER: 1
[DEBUG] ASN1_OCTET_STRING: public
[DEBUG] ASN1_GET_REQUEST_PDU: length = 42
[DEBUG] ASN1_INTEGER: 22870771
[DEBUG] ASN1_INTEGER: 0
[DEBUG] ASN1_INTEGER: 0
[DEBUG] ASN1_SEQUENCE: length = 28
[DEBUG] ASN1_SEQUENCE: length = 12
[DEBUG] ASN1_OBJECT_IDENTIFIER: 1.3.6.1.2.1.1.2.0
[DEBUG] ASN1_NULL: 0
[DEBUG] ASN1_SEQUENCE: length = 12
[DEBUG] ASN1_OBJECT_IDENTIFIER: 1.3.6.1.2.1.1.3.0
[DEBUG] ASN1_NULL: 0
[DEBUG] Sending 51 bytes of response
[DEBUG]
Hello Everybody:
I started the server successfully and write my config file and I had no problems.
but when I tried to send snmpset command to OID specified in config file I got the following error:
I tried to change community with no effects
the command I used is:
snmpset -v2c -c private 127.0.0.1:1235 (OID) s "newValue"
Is there any possible solutions?
or snmpset is not supported in the snmp simulator?
thanks for responding
After MVP and tests add - add usage examples and update description.
Implement MVP with the next functionality:
Sorry if this question is too basic but would we be able to setup a trap server with snmp-server?
Do I just use snmp-server on port 161 as the poll server and launch another snmp-server on port 162 to be used as the trap server?
Configuring each one appropriately.
Add unit tests
_write_int() is generating 8 octet length integer tlv for all integers (greater than zero), even if it takes less than 8 octets to represent them.
I realize there is handling of negative integers going on.
Partial fix is to always enable strip_trailing_zeroes. A complete fix would replicate the functionality that exists for negative numbers, for positive numbers. i.e. pack the appropriate size of bytes for the integer.
Partial fix:
add the line "strip_leading_zeros = True" at the beginning of _write_int() function
Also, there is a slight discrepancy between integer() and _write_int()
After this fix, integers on win32 netsnmp tools should work until you assign an integer value larger than 32 bits in your MIB (server config), just a heads up for everyone who is using precompiled win32 netsnmp tools on Windows.
tldr;
64-bit (8 octet) python integers making 32-bit compiled win32 netsnmp tools shart themselves.
It seems that the OIDS with Gauge32 does not like numbers between 32768 and 65535.
I'm assuming this is a user error and I'm feeding it incorrectly and am wondering how to do it right.
snmpset -v2c -c community_name host:port MIB::someName.1 'u' 40000
returns max value
_write_int() is generating 8 octet length integer tlv for all integers (greater than zero), even if it takes less than 8 octets to represent them.
I realize there is handling of negative integers going on. But this is not required based on the standard (ASN1 BER INTEGER).
Numeric data is encoded as unsigned integers with the least significant bit always first (to the right).
Partial fix is to always enable strip_trailing_zeroes. A complete fix would replicate the functionality that exists for negative numbers, for positive numbers. i.e. pack the appropriate size of bytes for the integer.
Partial fix:
add the line "strip_leading_zeros = True" at the beginning of _write_int() function
Also, there is a slight discrepancy between integer() and _write_int()
After this fix, integers on win32 netsnmp tools should work until you assign an integer value larger than 32 bits in your MIB (server config), just a heads up for everyone who is using precompiled win32 netsnmp tools on Windows.
tldr;
64-bit (8 octet) python integers making 32-bit compiled win32 netsnmp tools shart themselves.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.