Skip to main content

Python bindings for Hikvision SADP SDK

Project description

pysadp

pysadp 是一个基于 ctypes 的海康威视 SADP SDK Python 封装。

当前实现依据官方文档《SADPSDK_开发指南_V4.4_20231130.pdf》整理,适合在 Windows 环境中调用。

已封装能力

  • 启动和停止 SADP 服务
  • 搜索同网段在线设备
  • 手动刷新设备搜索
  • 激活设备
  • 修改设备网络参数
  • 获取设备加密串
  • 获取设备码
  • 重置密码
  • 透传 SADP_GetDeviceConfig
  • 透传 SADP_SetDeviceConfig

兼容性说明

  • 当前验证稳定的启动方式是 SADP_Start_V40
  • SADP_Start_V50 与跨网段搜索接口在当前 DLL 上未完全匹配,所以库中默认不启用
  • 重置密码接口优先尝试 SADP_ResetPasswd_V50,若 DLL 未导出,则自动回退到 SADP_ResetPasswd_V40

运行要求

  • Windows
  • Python 3.7+

如需实际搜索设备或操作网卡,通常需要管理员权限。

安装

pip install pysadp

如需使用自定义 SDK 目录,可通过 sdk_dir 参数或环境变量 PYSADP_SDK_DIR 指定。

快速示例

from pysadp import SADPClient

with SADPClient() as client:
    client.set_log_to_file(level=3, log_dir="sadp_logs", auto_delete=False)
    client.start()
    devices = client.discover(timeout=5.0)
    for device in devices:
        print(device.ipv4_address, device.mac, device.serial_no, device.is_activated)

激活设备

from pysadp import SADPClient

with SADPClient() as client:
    client.start()
    client.discover(timeout=5.0)
    client.activate_device("DS-2CDXXXXXXXXXXXX", "YourStrongPassword123")

修改网络参数

from pysadp import NetworkParameters, SADPClient

with SADPClient() as client:
    client.start()
    devices = client.discover(timeout=5.0)
    device = devices[0]
    params = NetworkParameters.from_device(device)
    params.ipv4_address = "192.168.1.120"
    params.ipv4_subnet_mask = "255.255.255.0"
    params.ipv4_gateway = "192.168.1.1"
    client.modify_device_network(device, "YourPassword123", params)

获取加密串和设备码

from pysadp import SADPClient

with SADPClient() as client:
    client.start()
    devices = client.discover(timeout=5.0)
    serial_no = devices[0].serial_no
    encrypt_string = client.get_encrypt_string(serial_no)
    safe_code = client.get_device_code(serial_no)
    print(encrypt_string.value)
    print(safe_code.value)

重置密码

from pysadp import ResetPasswordParameters, SADPClient

with SADPClient() as client:
    client.start()
    devices = client.discover(timeout=5.0)
    device = devices[0]

    params = ResetPasswordParameters.by_auth_file(
        password="NewPassword123",
        auth_file=r"C:\Encrypt_xxx.xml",
    )
    client.reset_password(device.serial_no, params)

CLI 用法

安装后可直接使用命令行:

pysadp discover

常用示例:

pysadp discover --timeout 5 --json
pysadp activate --serial DS-2CDXXXXXXXXXXXX --password NewPassword123
pysadp get-encrypt-string --serial DS-2CDXXXXXXXXXXXX
pysadp get-device-code --serial DS-2CDXXXXXXXXXXXX
pysadp modify-network --mac aa-bb-cc-dd-ee-ff --password Admin123 --ipv4-address 192.168.1.120 --ipv4-subnet-mask 255.255.255.0 --ipv4-gateway 192.168.1.1
pysadp reset-password --serial DS-2CDXXXXXXXXXXXX --new-password NewPassword123 --auth-file C:\Encrypt_xxx.xml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysadp-0.1.1.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysadp-0.1.1-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file pysadp-0.1.1.tar.gz.

File metadata

  • Download URL: pysadp-0.1.1.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pysadp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 08190cf97902d5109bda0cc36ec11b1f01091a2c6cface4b6341f4071751fb0f
MD5 c5ef7d13be0218d564310c33c7860587
BLAKE2b-256 c8aabeb7daad925a2c565be9e47ca3fa25f19cf37420324daa94e4c759e11621

See more details on using hashes here.

File details

Details for the file pysadp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pysadp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pysadp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3ca7e196952e6b48b34367a9e7a362da8d89f95a85dece9cf176c64c15717c9
MD5 1cd2e8c4a0ea2c5cf88f8d0cde67263f
BLAKE2b-256 c63c43a52995eef31faf71b953165373e0aafd7aae659774b2b027356875b84f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page