当前位置: 首页 > article >正文

Python:Netmiko实现网络设备巡检及配置备份

通过Python的第三方库Netmiko实现不同厂商网络设备的日常巡检及配置备份。一、设备列表文件JSON 文件1、 我们先看一个示例1拓扑2脚本import time from netmiko import ConnectHandler AR1 { host: 192.168.22.100, username: pytest, password: admin123, device_type: huawei_vrp } AR2 { host: 192.168.22.101, username: admin, password: pytest, device_type: huawei_vrp } AR1_connect ConnectHandler(**AR1) print(已成功登录设备 - AR1[host]) time.sleep(2) AR1_output AR1_connect.send_command(display version) print(AR1_output) AR1_connect.disconnect() AR2_connect ConnectHandler(**AR2) print(已成功登录设备 - AR2[host]) time.sleep(2) AR2_output AR2_connect.send_command(display ip interface brief) print(AR2_output) AR2_connect.disconnect()从上面的脚本可以看到我们定义了两台路由器设备并通过字典的形式保存了设备的信息。设备信息中host: 192.168.22.100, # host 为设备的IP地址username: pytest, # username 为SSH登录设备时使用的用户名password: admin123, # password 为用户密码device_type: huawei_vrp # device_type 为Netmiko所支持的设备类型Netmiko 当前可支持绝大多数厂商设备包括华为、H3C、TP-Link等通过支持的设备类型预设了一些指令。send_command() 用户执行查询、保存等命令AR1执行display versionAR2执行display ip interface brief3结果当有大量设备时脚本中就需要定义很多台设备信息每台设备都需要写一段连接执行的指令。下次再用时还得对所有信息进行修改2、设备列表文件JSON文件通过JSON文件可以将大量的设备信息保存在一个文件当中通过脚本来读取JSON文件中的设备信息。设备列表采用JSON文件保存{name: Layer3Switch-1, # 为设备名称可自定义也可使用设备当前名称connection: {device_type: huawei,host: 192.168.11.11,username: python,password: 123}}cisco设备登录后需进入特权模式所以JSON文件中会多一个enable_password的密码项。JSON 文件示例[ { name: HuaweiAR, connection: { device_type: huawei, host: 192.168.44.100, username: huaweipytest, password: HWpytest123 } }, { name: CiscoRouter, connection: { device_type: cisco_xe, host: 192.168.44.102, username: ciscopytest, password: Pythontest123 } }, { name: H3CAR, connection: { device_type: hp_comware, host: 192.168.44.101, username: h3cpytest, password: Pythontest123 } } ]二、脚本1、模块导入import os import json import logging import datetime from netmiko import ConnectHandler from netmiko.exceptions import NetMikoTimeoutException, NetMikoAuthenticationException2、获取脚本所在目录# 定义变量 SCRIPT_IDR获取脚本所在目录用于获取设备列表JSON文件同时巡检信息和配置备份也将在此目录保存 SCRIPT_DIR os.path.dirname(os.path.abspath(__file__)) # 也可指定自定义JOSN文件所在目录路径同样在脚本运行时也会在此目录生成巡检和配置备份目录 # SCRIPT_DIR rD:\BASE # 以Windows系统为例 # --- 自定义输出根目录脚本所在目录输出文件将保存在 ./backups 和 ./reports --- OUTPUT_BASE_DIR SCRIPT_DIR3、设备指令列表根据不同厂商设备提前设置好需要使用到的指令如需其他指令可在 ‘inspection_commands’中添加这里总结了华为、华三、Cisco如有其他厂商设备可追加# --- 厂商命令映射表 --- VENDOR_COMMANDS { huawei: { device_type: huawei, disable_paging: screen-length 0 temporary, backup_command: display current-configuration, inspection_commands: [ display device, display cpu-usage, display memory-usage, display ip interface brief, display logbuffer ] }, h3c: { device_type: hp_comware, disable_paging: screen-length disable, backup_command: display current-configuration, inspection_commands: [ display device, display cpu-usage, display memory, display ip interface brief, display logbuffer ] }, cisco: { device_type: cisco_ios, disable_paging: terminal length 0, backup_command: show running-config, inspection_commands: [ show version, show processes cpu, show processes memory, show ip interface brief, show logging ] } }4、创建函数 load_devices_from_json()用于从JSON文件中读取设备信息并重新对设备信息进行格式化并将所有设备的信息以列表的形式存放在变量 devices 中Netmiko库可直接使用 JSON 文件中的设备信息。为了确保正确性定义了一个单独的函数出来。如果 JSON 文件中有些设备的信息定义错误可通过函数获取到哪些设备的信息有误以便发现错误进行修改。def load_devices_from_json(filepath): try: with open(filepath, r, encodingutf-8) as f: raw_devices json.load(f) devices [] for item in raw_devices: device_name item.get(name, Unknown) conn_info item.get(connection, {}) device { name: device_name, device_type: conn_info.get(device_type), host: conn_info.get(host), username: conn_info.get(username), password: conn_info.get(password), port: conn_info.get(port, 22), enable_password: conn_info.get(enable_password, ), } if device[host] and device[username] and device[password]: devices.append(device) else: logging.warning(f设备 {device_name} 缺少必要连接信息已跳过。) logging.info(f成功从 {filepath} 加载了 {len(devices)} 台设备。) return devices except FileNotFoundError: logging.error(f错误设备清单文件 {filepath} 未找到。) return [] except json.JSONDecodeError as e: logging.error(f错误{filepath} 文件 JSON 格式无效{e}) return []5、接下来就是巡检和配置备份部分在这里分别定义了巡检和配置备份的函数。将JSON文件中预设置的指令进行格式化并将结果进行保存。在这里我们通过“device_type”来判断设备的厂商来执行相应指令。# --- 备份单台设备配置 --- def backup_device_config(conn, device_info, vendor, vendor_cmd): host device_info[host] device_name device_info.get(name, host) try: if vendor cisco: hostname_output conn.send_command(show running-config | include hostname) else: hostname_output conn.send_command(display current-configuration | include sysname) actual_hostname hostname_output.strip().split()[-1] except Exception: actual_hostname device_name logging.info(f--- 正在备份设备 {device_name} ({host}) 的配置 ---) backup_output conn.send_command(vendor_cmd[backup_command]) backup_dir os.path.join(OUTPUT_BASE_DIR, backups, vendor, str(datetime.date.today())) ensure_dir(backup_dir) filename f{backup_dir}/{actual_hostname}_{host}_{datetime.date.today()}.cfg with open(filename, w, encodingutf-8) as f: f.write(backup_output) logging.info(f✓ 设备 {device_name} 的配置已备份至{filename}) # --- 执行单台设备巡检 --- def inspect_device(conn, device_info, vendor, vendor_cmd): host device_info[host] device_name device_info.get(name, host) try: if vendor cisco: hostname_output conn.send_command(show running-config | include hostname) else: hostname_output conn.send_command(display current-configuration | include sysname) actual_hostname hostname_output.strip().split()[-1] except Exception: actual_hostname device_name report_dir os.path.join(OUTPUT_BASE_DIR, reports, vendor, str(datetime.date.today())) ensure_dir(report_dir) report_file f{report_dir}/{actual_hostname}_{host}_inspection.txt with open(report_file, w, encodingutf-8) as f: f.write(f设备 {actual_hostname} ({host}) 巡检报告 - {datetime.datetime.now()}\n) f.write(fJSON 定义名称{device_name}\n) f.write( * 60 \n\n) logging.info(f--- 正在巡检设备 {device_name} ({host}) ---) for cmd in vendor_cmd[inspection_commands]: f.write(f 执行命令: {cmd}\n) try: output conn.send_command(cmd, delay_factor2) f.write(output) except Exception as e: f.write(f!!! 命令执行失败: {str(e)}\n) f.write(\n - * 40 \n\n) logging.info(f✓ 设备 {device_name} 的巡检报告已生成至{report_file})6、最后是SSH登录设备。定义 process_device()函数来进行远程登录同样需要通过“device_type”来确定设备的厂商执行不同的登录需求。def process_device(device_info): host device_info[host] device_name device_info.get(name, host) device_type device_info[device_type] vendor None for v, cmd_set in VENDOR_COMMANDS.items(): if cmd_set[device_type] device_type: vendor v break if vendor is None: logging.error(f设备 {device_name} ({host}) 的设备类型 {device_type} 不受支持已跳过。) return vendor_cmd VENDOR_COMMANDS[vendor] netmiko_device { device_type: device_type, host: host, username: device_info[username], password: device_info[password], port: device_info.get(port, 22), enable_password: device_info.get(enable_password, ), conn_timeout: 60, auth_timeout: 30, } try: logging.info(f正在连接设备 {device_name} ({host})...) with ConnectHandler(**netmiko_device) as conn: if device_info.get(enable_password): conn.enable() conn.send_command_timing(vendor_cmd[disable_paging]) backup_device_config(conn, device_info, vendor, vendor_cmd) inspect_device(conn, device_info, vendor, vendor_cmd) except NetMikoTimeoutException: logging.error(f✗ 连接设备 {device_name} ({host}) 超时。) except NetMikoAuthenticationException: logging.error(f✗ 设备 {device_name} ({host}) 认证失败。) except Exception as e: logging.error(f✗ 处理设备 {device_name} ({host}) 时发生未知错误: {str(e)})7、所有的准备工作完成后便是将前期所有的操作进行整合完成想要达到的目的。完整代码如下import os import json import logging import datetime from netmiko import ConnectHandler from netmiko.exceptions import NetMikoTimeoutException, NetMikoAuthenticationException # --- 获取脚本所在目录 --- SCRIPT_DIR os.path.dirname(os.path.abspath(__file__)) # --- 配置日志 --- logging.basicConfig( format%(asctime)s - %(levelname)s - %(message)s, levellogging.INFO ) # --- 自定义输出根目录脚本所在目录输出文件将保存在 ./backups 和 ./reports --- OUTPUT_BASE_DIR SCRIPT_DIR # --- 厂商命令映射表 --- VENDOR_COMMANDS { huawei: { device_type: huawei, disable_paging: screen-length 0 temporary, backup_command: display current-configuration, inspection_commands: [ display device, display cpu-usage, display memory-usage, display ip interface brief, display logbuffer ] }, h3c: { device_type: hp_comware, disable_paging: screen-length disable, backup_command: display current-configuration, inspection_commands: [ display device, display cpu-usage, display memory, display ip interface brief, display logbuffer ] }, cisco: { device_type: cisco_ios, disable_paging: terminal length 0, backup_command: show running-config, inspection_commands: [ show version, show processes cpu, show processes memory, show ip interface brief, show logging ] } } # --- 辅助函数创建目录 --- def ensure_dir(directory): if not os.path.exists(directory): os.makedirs(directory) # --- 从 JSON 文件加载设备列表 --- def load_devices_from_json(filepath): try: with open(filepath, r, encodingutf-8) as f: raw_devices json.load(f) devices [] for item in raw_devices: device_name item.get(name, Unknown) conn_info item.get(connection, {}) device { name: device_name, device_type: conn_info.get(device_type), host: conn_info.get(host), username: conn_info.get(username), password: conn_info.get(password), port: conn_info.get(port, 22), enable_password: conn_info.get(enable_password, ), } if device[host] and device[username] and device[password]: devices.append(device) else: logging.warning(f设备 {device_name} 缺少必要连接信息已跳过。) logging.info(f成功从 {filepath} 加载了 {len(devices)} 台设备。) return devices except FileNotFoundError: logging.error(f错误设备清单文件 {filepath} 未找到。) return [] except json.JSONDecodeError as e: logging.error(f错误{filepath} 文件 JSON 格式无效{e}) return [] # --- 备份单台设备配置 --- def backup_device_config(conn, device_info, vendor, vendor_cmd): host device_info[host] device_name device_info.get(name, host) try: if vendor cisco: hostname_output conn.send_command(show running-config | include hostname) else: hostname_output conn.send_command(display current-configuration | include sysname) actual_hostname hostname_output.strip().split()[-1] except Exception: actual_hostname device_name logging.info(f--- 正在备份设备 {device_name} ({host}) 的配置 ---) backup_output conn.send_command(vendor_cmd[backup_command]) backup_dir os.path.join(OUTPUT_BASE_DIR, backups, vendor, str(datetime.date.today())) ensure_dir(backup_dir) filename f{backup_dir}/{actual_hostname}_{host}_{datetime.date.today()}.cfg with open(filename, w, encodingutf-8) as f: f.write(backup_output) logging.info(f✓ 设备 {device_name} 的配置已备份至{filename}) # --- 执行单台设备巡检 --- def inspect_device(conn, device_info, vendor, vendor_cmd): host device_info[host] device_name device_info.get(name, host) try: if vendor cisco: hostname_output conn.send_command(show running-config | include hostname) else: hostname_output conn.send_command(display current-configuration | include sysname) actual_hostname hostname_output.strip().split()[-1] except Exception: actual_hostname device_name report_dir os.path.join(OUTPUT_BASE_DIR, reports, vendor, str(datetime.date.today())) ensure_dir(report_dir) report_file f{report_dir}/{actual_hostname}_{host}_inspection.txt with open(report_file, w, encodingutf-8) as f: f.write(f设备 {actual_hostname} ({host}) 巡检报告 - {datetime.datetime.now()}\n) f.write(fJSON 定义名称{device_name}\n) f.write( * 60 \n\n) logging.info(f--- 正在巡检设备 {device_name} ({host}) ---) for cmd in vendor_cmd[inspection_commands]: f.write(f 执行命令: {cmd}\n) try: output conn.send_command(cmd, delay_factor2) f.write(output) except Exception as e: f.write(f!!! 命令执行失败: {str(e)}\n) f.write(\n - * 40 \n\n) logging.info(f✓ 设备 {device_name} 的巡检报告已生成至{report_file}) # --- 处理单台设备的主流程 --- def process_device(device_info): host device_info[host] device_name device_info.get(name, host) device_type device_info[device_type] vendor None for v, cmd_set in VENDOR_COMMANDS.items(): if cmd_set[device_type] device_type: vendor v break if vendor is None: logging.error(f设备 {device_name} ({host}) 的设备类型 {device_type} 不受支持已跳过。) return vendor_cmd VENDOR_COMMANDS[vendor] netmiko_device { device_type: device_type, host: host, username: device_info[username], password: device_info[password], port: device_info.get(port, 22), enable_password: device_info.get(enable_password, ), conn_timeout: 60, auth_timeout: 30, } try: logging.info(f正在连接设备 {device_name} ({host})...) with ConnectHandler(**netmiko_device) as conn: if device_info.get(enable_password): conn.enable() conn.send_command_timing(vendor_cmd[disable_paging]) backup_device_config(conn, device_info, vendor, vendor_cmd) inspect_device(conn, device_info, vendor, vendor_cmd) except NetMikoTimeoutException: logging.error(f✗ 连接设备 {device_name} ({host}) 超时。) except NetMikoAuthenticationException: logging.error(f✗ 设备 {device_name} ({host}) 认证失败。) except Exception as e: logging.error(f✗ 处理设备 {device_name} ({host}) 时发生未知错误: {str(e)}) # --- 主程序入口 --- if __name__ __main__: logging.info( 开始执行设备巡检与备份任务 ) # 使用脚本所在目录下的 devices.json devices_file os.path.join(SCRIPT_DIR, devices.json) devices load_devices_from_json(devices_file) if not devices: logging.error(设备列表为空脚本终止。) exit(1) for dev in devices: process_device(dev) logging.info( 所有任务执行完毕 )脚本使用设备列表文件和脚本放置在同一目录运行后会在当前目录脚本所在目录生成backups目录和reports目录分别存放配置文件和设备巡检运行状态文件。三、结果由于前面没有完成脚本的测试。今天在进行脚本测试时遇到了一个问题在脚本执行登录Cisco设备时未成功。当时认为是SSH 算法的问题但将所有的算法经过测试后还是失败了。后来通过获取了一下我所使用的netmiko版本支持的Cisco设备类型from netmiko.ssh_dispatcher import CLASS_MAPPER_BASE # 获取支持的设备列表 supported_devices list(CLASS_MAPPER_BASE.keys()) print(Netmiko支持的设备列表:) for device_type in sorted(supported_devices): print(f- {device_type})Netmiko支持的设备列表: - a10 - accedian - adtran_os - adva_fsp150f2 - adva_fsp150f3 - alcatel_aos - alcatel_sros - allied_telesis_awplus - apresia_aeos - arista_eos - arris_cer - aruba_os - aruba_osswitch - aruba_procurve - audiocode_66 - audiocode_72 - audiocode_shell - avaya_ers - avaya_vsp - broadcom_icos - brocade_fastiron - brocade_fos - brocade_netiron - brocade_nos - brocade_vdx - brocade_vyos - calix_b6 - casa_cmts - cdot_cros - centec_os - checkpoint_gaia - ciena_saos - cisco_asa - cisco_ftd - cisco_ios - cisco_nxos - cisco_s200 - cisco_s300 - cisco_tp - cisco_viptela - cisco_wlc - cisco_xe - cisco_xr - cloudgenix_ion - coriant - dell_dnos9 - dell_force10 - dell_isilon - dell_os10 - dell_os6 - dell_os9 - dell_powerconnect - dell_sonic - dlink_ds - eltex - eltex_esr - endace - enterasys - ericsson_ipos - ericsson_mltn63 - ericsson_mltn66 - extreme - extreme_ers - extreme_exos - extreme_netiron - extreme_nos - extreme_slx - extreme_tierra - extreme_vdx - extreme_vsp - extreme_wing - f5_linux - f5_ltm - f5_tmsh - flexvnf - fortinet - generic - generic_termserver - hillstone_stoneos - hp_comware - hp_procurve - huawei - huawei_olt - huawei_smartax - huawei_vrp - huawei_vrpv8 - ipinfusion_ocnos - juniper - juniper_junos - juniper_screenos - keymile - keymile_nos - linux - mellanox - mellanox_mlnxos - mikrotik_routeros - mikrotik_switchos - mrv_lx - mrv_optiswitch - netapp_cdot - netgear_prosafe - netscaler - nokia_srl - nokia_sros - oneaccess_oneos - ovs_linux - paloalto_panos - pluribus - quanta_mesh - rad_etx - raisecom_roap - ruckus_fastiron - ruijie_os - sixwind_os - sophos_sfos - supermicro_smis - teldat_cit - tplink_jetstream - ubiquiti_edge - ubiquiti_edgerouter - ubiquiti_edgeswitch - ubiquiti_unifiswitch - vyatta_vyos - vyos - watchguard_fireware - yamaha - zte_zxros - zyxel_os然后查看了一下我所使用的模拟器的设备版本Router#show version Cisco IOS XE Software, Version 17.03.01a Cisco IOS Software [Amsterdam], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.1a, RELEASE SOFTWARE (fc3) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2020 by Cisco Systems, Inc. Compiled Tue 11-Aug-20 23:56 by mcpre Cisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc. All rights reserved. Certain components of Cisco IOS-XE software are licensed under the GNU General Public License (GPL) Version 2.0. The software code licensed under GPL Version 2.0 is free software that comes with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such GPL code under the terms of GPL Version 2.0. For more details, see the documentation or License Notice file accompanying the IOS-XE software, or the applicable URL provided on the flyer accompanying the IOS-XE software. ROM: IOS-XE ROMMON于是就将JSON文件中Cisco设备的 device_type 修改为 cisco_xe脚本顺利执行

相关文章:

Python:Netmiko实现网络设备巡检及配置备份

通过Python的第三方库Netmiko实现不同厂商网络设备的日常巡检及配置备份。一、设备列表文件:JSON 文件1、 我们先看一个示例(1)拓扑(2)脚本import time from netmiko import ConnectHandlerAR1 {"host": &q…...

基于Web Audio与Canvas实现浏览器端音视频动态合成

1. 项目概述与核心价值最近在折腾一些个人项目,想给静态页面加点“活”的交互,比如让用户上传一张图片,然后生成一个带点律动感的音乐视频。这听起来像是需要一整套复杂的音视频处理流水线,从音频分析到视觉生成,没个几…...

Python实现本地网络摄像头服务器:MJPEG流原理与Flask部署实战

1. 项目概述:从“玩具”到“利器”的本地网络摄像头如果你手头有一台闲置的旧手机、一个吃灰的USB摄像头,或者只是想用电脑自带的摄像头搭建一个简单的监控、直播或视频会议服务器,那么mehmetkahya0/local-web-camera这个项目绝对值得你花时间…...

3个维度解析Backtrader-PyQt可视化回测平台:从零到策略实战的完整指南

3个维度解析Backtrader-PyQt可视化回测平台:从零到策略实战的完整指南 【免费下载链接】backtrader-pyqt-ui 项目地址: https://gitcode.com/gh_mirrors/bac/backtrader-pyqt-ui 在量化交易的世界里,策略回测常常是开发者最头疼的环节——要么面…...

现代化终端模拟器开发:从原理到实践,构建智能开发环境

1. 项目概述:一个面向未来的终端模拟器在开发者的日常工作中,终端(Terminal)是连接我们与计算机系统核心的桥梁。无论是进行服务器运维、代码编译、版本控制还是日常的文件操作,一个高效、稳定且功能强大的终端模拟器&…...

Vanna 2.0企业级部署:基于LLM智能体的自然语言转SQL与权限控制实战

1. 项目概述:从自然语言到数据洞察的智能桥梁在数据驱动的时代,数据分析师和业务人员之间似乎总隔着一道无形的墙。业务人员用自然语言提问:“上个季度华东区的销售冠军是谁?”,而分析师则需要将其翻译成复杂的SQL查询…...

AI智能体编排平台d3vsh0p:从需求到代码的自动化软件开发实践

1. 项目概述:一个由AI驱动的自主软件开发平台 如果你和我一样,经历过无数次从零开始构建一个软件项目的繁琐过程——写需求文档、设计架构、编码、测试、调试,再到最后的部署和维护——你可能会想,有没有一种方式能让这个过程更自…...

别再怕单点故障了!用HCL模拟器手把手搭建M-LAG双活核心网络(附完整配置与排错)

别再怕单点故障了!用HCL模拟器手把手搭建M-LAG双活核心网络(附完整配置与排错) 当核心交换机突然宕机,整个办公区网络瘫痪的红色警报在监控屏上闪烁时,我正端着咖啡准备开始周一晨会。这种场景对任何网络管理员来说都是…...

FreeSWITCH与AI大模型融合:构建智能语音交互系统核心架构

1. 项目概述:当FreeSWITCH遇上AI语音交互最近在折腾一个挺有意思的玩意儿,把FreeSWITCH这个老牌的开源软交换平台,和当下火热的AI大语言模型(比如ChatGPT)给打通了。项目名字就叫laoyin/freeswitch_chatGPT&#xff0c…...

多平台内容分发系统架构设计与实现思路 行业通用技术方案解析

前言从后端开发与系统架构设计视角来看,当下很多技术团队、自媒体工作室、企业运营部门,都有搭建多平台内容矩阵分发系统的需求。无论是技术博文跨平台同步、企业官方内容统一发布,还是垂直领域账号矩阵运维,本质上都需要一套标准…...

DSP F28335 ADC配置避坑指南:从官方例程到实战,我踩过的那些时钟和采样模式的坑

DSP F28335 ADC实战避坑手册:时钟配置与采样模式的高效调优策略 第一次接触F28335的ADC模块时,我像大多数工程师一样,直接套用了TI官方例程的配置参数。结果在电机控制项目中,采样值总是出现周期性波动,导致PID调节异常…...

AAEON PICO-ASL4工业级Pico-ITX单板计算机解析与应用

1. AAEON PICO-ASL4工业级Pico-ITX单板计算机深度解析在工业自动化和边缘计算领域,对小型化、低功耗且高性能计算设备的需求日益增长。AAEON推出的PICO-ASL4正是针对这一需求设计的解决方案。这款采用Pico-ITX规格的单板计算机(SBC)集成了Intel最新的Atom x7000RE系…...

Anthropic Claude API用户代理插件:伪装请求头绕过限制与优化调用

1. 项目概述与核心价值 最近在折腾一些AI应用开发,发现一个挺有意思的GitHub项目: tenorduckpate119/opencode-anthropic-user-agent-plugin 。乍一看这个仓库名有点长,但拆解一下就能明白它的核心价值——这是一个针对Anthropic Claude A…...

以物理定律约束智能算法,用镜像技术重构时空感知

以物理定律约束智能算法,用镜像技术重构时空感知——镜像视界新一代空间智能可信技术白皮书前言当下空间智能与数字孪生产业,深陷纯数据驱动算法脱离物理逻辑、时空感知失真、推演结果不可控、系统可信度不足的行业困境,智能算法黑箱、时空基…...

DeepSeek-V4-pro 接入 Claude Code 教程

本教程介绍了如何将 DeepSeek 的最新模型(V4 Flash / V4 Pro)通过 API 的方式接入 Claude Code,打造极具性价比的本地 AI 智能代理,并解锁百万级上下文与最高思考等级。 核心亮点 绕过官方模型限制:无订阅也可使用 C…...

基于 Simulink 的数字控制延时补偿与稳定性分析深度实战教程

目录 🎯 一、 核心痛点:为什么算法上板就“发疯”? 🛠️ 二、 详细建模过程:复现“炸机”现场 第一步:搭建含真实延时的被控对象 第二步:频域透视——伯德图验证 💻 三、 核心代码与算法实现 策略 A:一拍超前预测(One-Step-Ahead Prediction) 策略 B:改进…...

基于Simulink的储能变流器(PCS)并网预同步与离/并网无缝切换控制​

目录 手把手教你学Simulink——基于Simulink的储能变流器(PCS)并网预同步与离/并网无缝切换控制​ 摘要​ 一、背景与挑战​...

想在Win10任务栏显示秒数?试试用StartAllBack配合注册表修改(附详细步骤)

在Windows 10任务栏精准显示秒数的完整方案 每次盯着任务栏的时间区域,总觉得少了点什么?对于需要精确计时的工作场景——比如直播倒计时、程序调试或是单纯的时间强迫症患者来说,系统默认隐藏秒数的设计确实不够友好。虽然微软在Windows 10…...

千问 LeetCode 2127.参加会议的最多员工数 public int maximumInvitations(int[] favorite)

这道题是图论中的经典问题,考察的是基环树的处理。🧠 题目分析1. 建模:将员工看作图的节点,favorite[i] 表示从节点 i 指向节点 favorite[i] 的一条有向边。 2. 图的结构:由于每个节点出度为 1,这个图由若…...

Python初学者项目练习9--对简单列表元素排序

一、练习题目 给定一个简单列表,对其元素进行排序简单列表:元素类型不是复合类型(列表/元组/字典) 示例: 形式1:[10,20,30,40] 形式2:[‘aa’, ‘bb’, ‘cc’…...

【赵渝强老师】Hadoop的伪分布部署模式

Hadoop的安装和部署是大数据生态圈体系中最麻烦的一个。Hadoop部署完成后,进一步地部署Spark和Flink就非常容易了。Hadoop的部署模式分为本地模式、伪分布模式和全分布模式。在学习完成了ZooKeeper的相关内容后,还将进一步地学习Hadoop HA的部署。这里重…...

千问 LeetCode 2122.还原原数组 public int[] recoverArray(int[] nums)

这道题的核心思路是枚举 双指针验证。🧠 解题思路1. 排序:首先将 nums 数组排序。排序后,最小的元素 nums[0] 必然是原数组某个元素减去 k 得到的(即 lower 数组中的最小值)。 2. 枚举 k:我们遍历排序后…...

Ising机与Bounce-Bind机制在组合优化中的应用

1. Ising机与组合优化问题概述在计算复杂性理论中,组合优化问题(Combinatorial Optimization Problems, COPs)因其NP难特性而闻名。这类问题在物流调度、芯片设计、金融投资组合等领域广泛存在。传统计算机采用冯诺依曼架构,其串行…...

硬件设计避坑:PMOS缓启动电路关断慢?实测教你优化栅极泄放回路(含仿真文件)

PMOS缓启动电路优化实战:栅极泄放回路设计与关断性能提升 引言 在电源管理系统中,PMOS管因其低导通电阻和简单驱动特性,常被用作电源开关。但当负载端存在较大容性负载时,直接开关可能导致瞬间大电流冲击,因此缓启动电…...

专业干货:AI教材写作全攻略,低查重技巧与优质工具大揭秘!

编写教材的过程,总是避免不了那些“慢节奏”的烦恼。尽管已经整理好框架和资料,却总是被内容创作所困扰——一段话反复推敲了半个小时,仍觉得表达不够理想;章节之间的连接语,绞尽脑汁也想不出合适的措辞,写…...

用立创EDA复刻蓝桥杯省赛真题电路:手把手搭建一个简易电压采集与显示系统(2022模拟题2)

用立创EDA复刻蓝桥杯省赛真题电路:手把手搭建一个简易电压采集与显示系统 在电子设计竞赛的备赛过程中,真题复现是最有效的实战训练方式之一。2022年蓝桥杯省赛模拟题中的电压采集与显示系统,融合了模拟信号处理、数字显示和存储等典型电路模…...

Java调用海康SDK的NET_DVR_STDXMLConfig接口,手把手教你获取设备信息(附完整代码)

Java调用海康SDK的NET_DVR_STDXMLConfig接口实战指南 对于需要与海康威视设备深度集成的Java开发者来说,NET_DVR_STDXMLConfig接口是一个强大但容易踩坑的工具。本文将带你从零开始,理解这个接口的工作原理,并提供一个完整的、可直接运行的代…...

【Redis】Redis——过期键删除策略、内存淘汰8种策略、LRU/LFU实现

文章目录Redis——过期键删除、内存淘汰、LRU/LFU实现一、核心概念前置区分(90%使用者的混淆点)二、Redis 过期键删除策略2.1 过期键的底层存储2.2 行业通用的3种过期删除策略2.3 Redis 实际采用的组合策略(惰性删除 定期删除)2.…...

别再死记硬背async/await了!用Playwright+Python写自动化脚本,这3个坑我帮你踩过了

别再死记硬背async/await了!用PlaywrightPython写自动化脚本,这3个坑我帮你踩过了 第一次用Playwright写自动化测试脚本时,我对着文档里的async/await关键字发呆了半小时。明明照着示例代码敲了一遍,运行时却总是报错。后来才发现…...

RTX 3050 + Win11实测:Python 3.10环境下,用pip搞定TensorFlow-GPU 2.10.1的完整避坑指南

RTX 3050 Win11实战:Python 3.10环境下的TensorFlow-GPU 2.10.1终极配置手册 在Windows 11系统上配置TensorFlow-GPU环境,尤其是搭配NVIDIA RTX 3050这样的主流显卡时,往往会遇到各种版本冲突和环境配置问题。本文将带你一步步完成从零开始…...