Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uploader snmp md file #1

Merged
merged 7 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# QuecPython SNMP

[中文](./README_ZH.md) | English

## Overview

The Simple Network Management Protocol (SNMP) is a communication protocol used for managing and monitoring network devices in IP networks, applicable to routers, switches, servers, and other devices. Its design is lightweight and highly scalable, supporting various operating systems and network equipment. SNMP uses community strings as a simple means of access control, allowing network administrators to collect and manage device information.

The main SNMP operations include GET, used to request device information; SET, used to modify device configurations; and TRAP, used for devices to report anomalies to the management station. As the protocol has evolved, SNMP has enhanced its security features. The latest version, SNMPv3, supports message integrity, authentication, and encryption to improve communication security.

## Usage

- [API_Reference](./docs/en/API_Reference.md)
- [Sample Code](./code/snmp_api.py)
- [SNMP Documentation](./docs/en/SNMP_Documentation.md)

## Contribution

We welcome contributions to improve this project! Please follow these steps to contribute:

1. Fork this repository.
2. Create a new branch (`git checkout -b feature/your-feature`).
3. Commit your changes (`git commit -m 'Add your feature'`).
4. Push to the branch (`git push origin feature/your-feature`).
5. Open a Pull Request.

## License

This project is licensed under the Apache License. For more details, please see the [LICENSE](./LICENSE) file.

## Support

If you have any questions or need support, please refer to the [QuecPython Documentation](https://python.quectel.com/doc) or open an issue in this repository.
33 changes: 33 additions & 0 deletions README_ZH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# QuecPython SNMP协议

中文| [English](./README.md)

## 概述

简单网络管理协议(SNMP)是一种在IP网络中用于管理和监控网络设备的通信协议,适用于路由器、交换机、服务器等设备。它的设计轻量而且扩展性强,能够支持各种操作系统和网络设备。SNMP使用社区字符串作为一种简单的访问控制手段,允许网络管理员收集和管理设备信息。

SNMP主要操作包括GET,用于请求设备信息;SET,用于修改设备配置;以及TRAP,用于设备向管理站报告异常。随着版本的发展,SNMP增加了安全功能,最新的SNMPv3版本支持消息完整性、认证和加密,以提高通信安全。

## 用法

- [API说明文档](./docs/zh/API说明文档.md)
- [示例代码](./code/snmp_api.py)
- [SNMP使用文档](./docs/zh/SNMP使用文档.md)

## 贡献

我们欢迎对本项目的改进做出贡献!请按照以下步骤进行贡献:

1. Fork 此仓库。
2. 创建一个新分支(`git checkout -b feature/your-feature`)。
3. 提交您的更改(`git commit -m 'Add your feature'`)。
4. 推送到分支(`git push origin feature/your-feature`)。
5. 打开一个 Pull Request。

## 许可证

本项目使用 Apache 许可证。详细信息请参阅 [LICENSE](./LICENSE) 文件。

## 支持

如果您有任何问题或需要支持,请参阅 [QuecPython 文档](https://python.quectel.com/doc) 或在本仓库中打开一个 issue。
192 changes: 96 additions & 96 deletions hmac.py → code/hmac.py
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
import uhashlib
trans_5C = bytes((x ^ 0x5C) for x in range(256))
trans_36 = bytes((x ^ 0x36) for x in range(256))
digest_size = None
_secret_backdoor_key = []
def translate(d, t):
return bytes(t[x] for x in d)
class HMAC:
blocksize = 64 # 512-bit HMAC; can be changed in subclasses.
def __init__(self, key, msg=None, digestmod=None):
if key is _secret_backdoor_key: # cheap
return
if digestmod == "md5":
digestmod = uhashlib.md5
self.digest_size = 16
elif digestmod == "sha1":
digestmod = uhashlib.sha1
self.digest_size = 20
if hasattr(digestmod, '__call__'):
self.digest_cons = digestmod
else:
self.digest_cons = digestmod
self.outer = self.digest_cons()
self.inner = self.digest_cons()
if hasattr(self.inner, 'block_size'):
blocksize = self.inner.block_size
if blocksize < 16:
blocksize = self.blocksize
else:
blocksize = self.blocksize
if len(key) > blocksize:
key = self.digest_cons(key).digest()
key = key + chr(0) * (blocksize - len(key))
self.outer.update(translate(key, trans_5C))
self.inner.update(translate(key, trans_36))
if msg is not None:
self.update(msg)
@property
def name(self):
return "hmac-" + self.inner.name
def update(self, msg):
"""Update this hashing object with the string msg.
"""
self.inner.update(msg)
def copy(self):
"""Return a separate copy of this hashing object.
An update to this copy won't affect the original object.
"""
# Call __new__ directly to avoid the expensive __init__.
other = self.__class__.__new__(self.__class__)
other.digest_cons = self.digest_cons
other.digest_size = self.digest_size
other.inner = self.inner
other.outer = self.outer
return other
def _current(self):
"""Return a hash object for the current state.
To be used only internally with digest() and hexdigest().
"""
h = self.outer
h.update(self.inner.digest())
return h
def digest(self):
"""Return the hash value of this hashing object.
This returns a string containing 8-bit data. The object is
not altered in any way by this function; you can continue
updating the object after calling this function.
"""
h = self._current()
return h.digest()
def hexdigest(self):
"""Like digest(), but returns a string of hexadecimal digits instead.
"""
h = self._current()
return h.hexdigest()
def new(key, msg=None, digestmod=None):
return HMAC(key, msg, digestmod)
import uhashlib
trans_5C = bytes((x ^ 0x5C) for x in range(256))
trans_36 = bytes((x ^ 0x36) for x in range(256))

digest_size = None

_secret_backdoor_key = []


def translate(d, t):
return bytes(t[x] for x in d)

class HMAC:
blocksize = 64 # 512-bit HMAC; can be changed in subclasses.

def __init__(self, key, msg=None, digestmod=None):
if key is _secret_backdoor_key: # cheap
return

if digestmod == "md5":
digestmod = uhashlib.md5
self.digest_size = 16
elif digestmod == "sha1":
digestmod = uhashlib.sha1
self.digest_size = 20
if hasattr(digestmod, '__call__'):
self.digest_cons = digestmod
else:
self.digest_cons = digestmod

self.outer = self.digest_cons()
self.inner = self.digest_cons()

if hasattr(self.inner, 'block_size'):
blocksize = self.inner.block_size
if blocksize < 16:
blocksize = self.blocksize
else:
blocksize = self.blocksize

if len(key) > blocksize:
key = self.digest_cons(key).digest()

key = key + chr(0) * (blocksize - len(key))
self.outer.update(translate(key, trans_5C))
self.inner.update(translate(key, trans_36))
if msg is not None:
self.update(msg)

@property
def name(self):
return "hmac-" + self.inner.name

def update(self, msg):
"""Update this hashing object with the string msg.
"""
self.inner.update(msg)

def copy(self):
"""Return a separate copy of this hashing object.
An update to this copy won't affect the original object.
"""
# Call __new__ directly to avoid the expensive __init__.
other = self.__class__.__new__(self.__class__)
other.digest_cons = self.digest_cons
other.digest_size = self.digest_size
other.inner = self.inner
other.outer = self.outer
return other

def _current(self):
"""Return a hash object for the current state.
To be used only internally with digest() and hexdigest().
"""
h = self.outer
h.update(self.inner.digest())
return h

def digest(self):
"""Return the hash value of this hashing object.
This returns a string containing 8-bit data. The object is
not altered in any way by this function; you can continue
updating the object after calling this function.
"""
h = self._current()
return h.digest()

def hexdigest(self):
"""Like digest(), but returns a string of hexadecimal digits instead.
"""
h = self._current()
return h.hexdigest()


def new(key, msg=None, digestmod=None):
return HMAC(key, msg, digestmod)
Loading