IPSec scale config script over Cisco Router

Pandas入门教程(二十二):股票数据分析实战——yfinance 获取数据、技术指标与收益率分析 把 Pandas 用在真实场景,才能体会它的价值。本文以茅台股票为例,用 yfinance 获取历史行情,完成缺失值处理与列筛选,绘制收盘价曲线,计算 SMA 移动平均线与 RSI 相对强弱指数,并通过日收益率、累计收益率和波动率完成完整的量化分析流程。 阅读详情

该脚本支持了SVTI模式的config scale


from xml.dom import minidom
from ftplib import FTP
import telnetlib
import sys
import time
import logging
import os
import re
import platform
import string

class IPSecConfigScale:
    def __init__(self, tunnel, mode):
        self.__tunnel_number__ = int(tunnel)
        self.__mode__ = mode
        
        self.__vlan_start__ = 2000
        
        self.__ip_wan_A__ = '50.1.'
        self.__ip_wan_B__ = self.__ip_wan_A__
        self.__ip_lan_A__ = '172.16.'
        self.__ip_lan_B__ = '172.17.'
        self.__netmask__ = '255.255.255.0'
        self.__wildcard__ = '0.0.0.255'
        self.__interface_lan_A__ = 'GigabitEthernet2.'
        self.__interface_wan_A__ = 'GigabitEthernet3.'
        self.__interface_lan_B__ = 'GigabitEthernet2.'
        self.__interface_wan_B__ = 'GigabitEthernet3.'
        
        self.__vlan_lan_A__ = 2000
        self.__vlan_wan__ = 3000
        self.__vlan_lan_B__ = 4000
        
        self.__eigrp_as__ = 1000
        
        return
        
    def run(self):
    	print 'tunnel is %s' % self.__tunnel_number__
    	print 'mode is %s' % self.__mode__
    	
    	if self.__tunnel_number__ >= 255:
    	    print 'ERROR, %s is not supported' % self.__tunnel_number__

    	if mode == 'ikev2':
    		self.__scale_ikev2_config__(ip_lan_local_in = self.__ip_lan_A__, 
    		    ip_wan = self.__ip_wan_A__, 
    		    ip_lan_remote_in=self.__ip_lan_B__, 
    		    interface_lan = self.__interface_lan_A__, 
    		    interface_wan = self.__interface_wan_A__, 
    		    vlan_lan_in=self.__vlan_lan_A__, 
    		    vlan_wan_in=self.__vlan_wan__, 
    		    role=1)
    		self.__scale_ikev2_config__(ip_lan_local_in = self.__ip_lan_B__, 
    		    ip_wan = self.__ip_wan_B__, 
    		    ip_lan_remote_in=self.__ip_lan_A__, 
    		    interface_lan = self.__interface_lan_B__, 
    		    interface_wan = self.__interface_wan_B__, 
    		    vlan_lan_in=self.__vlan_lan_B__, 
    		    vlan_wan_in=self.__vlan_wan__, 
    		    role=2)
    	elif mode == 'svti':
    		self.__scale_svti_config__()
    	else:
    		print '%s is not supported'
    		
    	return

    def __scale_svti_config__(self):
        self.__svti_wan_ip_A__ = '192.168.1.1'
        self.__svti_wan_ip_B__ = '192.168.1.2'
        self.__svti_wan_interface_A__ = 'GigabitEthernet2.880'
        self.__svti_wan_interface_B__ = 'GigabitEthernet0/0/0.880'
                
        self.__svti_interface_loopback__ = 1000
        
        self.__svti_loopback_ip_A__ = '10.1'
        self.__svti_loopback_ip_B__ = '10.2'
        
        self.__svti_tunnel_ip_A__ = '80.1'
        self.__svti_tunnel_ip_B__ = '80.1'
        
        self.__svti_network__ = '255.255.255.0'
        
        
    	print '###################################'
    	print '###################################'
    	print '# config for Cisco Router A:'
    	print 'configure terminal'
    	print 'interface %s' % self.__svti_wan_interface_A__
    	print '  ip address %s %s' % (self.__svti_wan_ip_A__, self.__svti_network__)
    	print 'crypto keyring KEYS'  
    	print '  pre-shared-key address 0.0.0.0 0.0.0.0 key cisco'
    	print 'crypto isakmp policy 10'
    	print ' encr 3des'
    	print ' hash sha256'
    	print ' authentication pre-share'
    	print ' group 2'
    	print ' lifetime 600'
    	print 'crypto isakmp profile ISAKMPP'
    	print '   keyring KEYS'
    	print '   match identity address 0.0.0.0' 
    	print 'crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac'
    	print ' mode tunnel'
    	print 'crypto ipsec profile IPSECPP'
    	print ' set transform-set TS'
    	print ' set isakmp-profile ISAKMPP'
    	
    	for it in range(0, self.__tunnel_number__):
    	    number = self.__svti_interface_loopback__ + it
    	    svti_loopback_ip_A = '%s.%s.1' % (self.__svti_loopback_ip_A__, it)
    	    svti_loopback_ip_B = '%s.%s.1' % (self.__svti_loopback_ip_B__, it)
    	    svti_tunnel_ip_A = '%s.%s.1' % (self.__svti_tunnel_ip_A__, it)
    	    
    	    print 'interface loopback %s' % number
    	    print '  ip address %s %s' % (svti_loopback_ip_A, self.__svti_network__)
    	    
    	    print 'interface tunnel %s' % number
    	    print '  ip address %s %s' % (svti_tunnel_ip_A, self.__svti_network__)
    	    print '  tunnel source loopback %s' % number
    	    print '  tunnel mode ipsec ipv4'
    	    print '  tunnel destination %s' % svti_loopback_ip_B
    	    print '  tunnel protection ipsec profile IPSECPP'

    	print 'end'
    	    	
        print '###################################'
    	print '###################################'
    	print '# config for Cisco Router B:'
    	print 'configure terminal'
    	print 'interface %s' % self.__svti_wan_interface_B__
    	print '  ip address %s %s' % (self.__svti_wan_ip_B__, self.__svti_network__)
    	print 'crypto keyring KEYS'  
    	print '  pre-shared-key address 0.0.0.0 0.0.0.0 key cisco'
    	print 'crypto isakmp policy 10'
    	print ' encr 3des'
    	print ' hash sha256'
    	print ' authentication pre-share'
    	print ' group 2'
    	print ' lifetime 600'
    	print 'crypto isakmp profile ISAKMPP'
    	print '   keyring KEYS'
    	print '   match identity address 0.0.0.0' 
    	print 'crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac'
    	print ' mode tunnel'
    	print 'crypto ipsec profile IPSECPP'
    	print ' set transform-set TS'
    	print ' set isakmp-profile ISAKMPP'
    	
    	for it in range(0, self.__tunnel_number__):
    	    number = self.__svti_interface_loopback__ + it
    	    svti_loopback_ip_A = '%s.%s.1' % (self.__svti_loopback_ip_A__, it)
    	    svti_loopback_ip_B = '%s.%s.1' % (self.__svti_loopback_ip_B__, it)
    	    svti_tunnel_ip_B = '%s.%s.1' % (self.__svti_tunnel_ip_B__, it)
    	    
    	    print 'interface loopback %s' % number
    	    print '  ip address %s %s' % (svti_loopback_ip_B, self.__svti_network__)
    	    
    	    print 'interface tunnel %s' % number
    	    print '  ip address %s %s' % (svti_tunnel_ip_B, self.__svti_network__)
    	    print '  tunnel source loopback %s' % number
    	    print '  tunnel mode ipsec ipv4'
    	    print '  tunnel destination %s' % svti_loopback_ip_A
    	    print '  tunnel protection ipsec profile IPSECPP'

    	print 'end'
    	
    	print '###################################'
    	print '###################################'
    	print '# unconfig for Cisco Router A and B:'
    	print 'configure terminal'
    	
    	for it in range(0, self.__tunnel_number__):
    	    number = self.__svti_interface_loopback__ + it
            print 'no interface tunnel %s' % number
    	    print 'no interface loopback %s' % number

        print 'no crypto ipsec profile IPSECPP'
        print 'no crypto isakmp profile ISAKMPP'
        print 'no crypto keyring KEYS'
        print 'no crypto isakmp policy 10'
        print 'no crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac'

    	print 'end'
        
        return 
    	    	
    def __scale_ikev2_config__(self, ip_lan_local_in='172.16.', 
            ip_wan='50.1.', 
            ip_lan_remote_in='60.1.', 
            interface_lan='GigabitEthernet2.', 
            interface_wan='GigabitEthernet3.', 
            vlan_lan_in=2000, 
            vlan_wan_in=3000, 
            role=1):
    	
    	print '###################################'
    	print '###################################'
    	print '# config for Cisco Router(role: %s):' % role
    	print 'configure terminal'
    	for it in range(0, self.__tunnel_number__):
    	    proposal = 'IKEv2Proposal%s' % it
    	    policy = 'IKEv2Policy%s' % it
    	    key = 'KEY%s' % it
    	    peer = 'PEER%s' % it
    	    profile = 'IKEv2Profile%s' % it
    	    transform_set = 'TS%s' % it
    	    map = 'CMAP%s' % it

    	    vlan_lan = vlan_lan_in + it
    	    vlan_wan = vlan_wan_in + it
    	        	    
    	    if role == 1:
    	        ip_wan_local =  '%s%s.1' % (ip_wan, it) 
    	        ip_wan_remote = '%s%s.2' % (ip_wan, it) 
    	    else:
    	        ip_wan_local =  '%s%s.2' % (ip_wan, it) 
    	        ip_wan_remote = '%s%s.1' % (ip_wan, it) 
    	        
    	    ip_lan_local = '%s%s.%s' % (ip_lan_local_in, it, 1)
    	    ip_lan_remote = '%s%s.%s' % (ip_lan_remote_in, it, 1)
    	        	        
    	    subinterface_lan = '%s%s' % (interface_lan, vlan_lan)
    	    subinterface_wan = '%s%s' % (interface_wan, vlan_wan)
    	    
    	    traffic_acl = 'traffic_acl_%s' % it
    	    
    	    eigrp_as = 1000 +it

    	    # traffic acl
    	    print '# traffic ACL'
            print 'ip access-list extended %s' % traffic_acl
            print ' permit ip host %s any' % ip_lan_local
            print ' permit ip host %s any' % ip_lan_remote
    	    
    	    # ikev2 proposal
    	    print '# IKEv2 proposal'
            print 'crypto ikev2 proposal %s' % proposal
            print '  encryption 3des'
            print '  integrity sha512'
            print '  group 2'
            
            # ikev2 policy
    	    print '# IKEv2 policy'
            print 'crypto ikev2 policy %s' % policy
            print '  proposal %s' % proposal
            
            # ikev2 keyring
    	    print '# IKEv2 keyring'
            print 'crypto ikev2 keyring %s' % key
            print '  peer %s' % peer
            print '    address %s' % ip_wan_remote
            print '    pre-shared-key local cisco123'
            print '    pre-shared-key remote cisco123'
            
            # ikev2 profile
    	    print '# IKEv2 profile'
            print 'crypto ikev2 profile %s' % profile
            print '  match identity remote address %s 255.255.255.255' % ip_wan_remote
            print '  identity local address %s' % ip_wan_local
            print '  authentication local pre-share'
            print '  authentication remote pre-share'
            print '  keyring local %s' % key
            
            # ipsec transform-set
    	    print '# IPSec transform-set'
            print 'crypto ipsec transform-set %s esp-aes 256 esp-sha256-hmac' % transform_set

            # crypto map
    	    print '# crypto map'
            print 'crypto map %s 10 ipsec-isakmp' % map
            print ' set peer %s' % ip_wan_remote
            print ' set transform-set %s' % transform_set
            print ' set ikev2-profile %s' % profile
            print ' match address %s' % traffic_acl
            
            # subinterface wan
    	    print '# wan subinterface'
            print 'interface %s' % subinterface_wan
            print '  encapsulation dot1q %s' % vlan_wan
            print '  ip address %s %s' % (ip_wan_local, self.__netmask__)
            print '  crypto map %s' % map

            # subinterface lan
    	    print '# lan subinterface'
            print 'interface %s' % subinterface_lan
            print '  encapsulation dot1q %s' % vlan_lan
            print '  ip address %s %s' % (ip_lan_local, self.__netmask__)
            
            # static route
            print 'ip route %s 255.255.255.255 %s' % (ip_lan_remote, ip_wan_remote)
            
            print 'end'
    	return
    	
    	
def printHelp():
    print '\nError running command!\n\n'
    print 'Please run it as following indication:'
    print 'COMMAND <tunnel number> [mode]\n'
    print 'For Example:'
    print '    python IPSecConfigScale.py 10 ikev2\n\n'
    
    return -1

if __name__ == "__main__":
    numargs = len(sys.argv) - 1

    if numargs == 0:
    	tunnel = 10
    	mode = 'ikev2'
    elif numargs == 1:
        tunnel = sys.argv[1]
        mode = 'ikev2'
    elif numargs == 2:
        tunnel = sys.argv[1]
        mode = sys.argv[2]
    else:
    	printHelp()
        sys.exit(1)
        
    scale = IPSecConfigScale(tunnel, mode)
    scale.run()


运行情况:


python ipsec_config_scale.py 2 svti
tunnel is 2
mode is svti
###################################
###################################
# config for Cisco Router A:
configure terminal
interface GigabitEthernet2.880
  ip address 192.168.1.1 255.255.255.0
crypto keyring KEYS
  pre-shared-key address 0.0.0.0 0.0.0.0 key cisco
crypto isakmp policy 10
 encr 3des
 hash sha256
 authentication pre-share
 group 2
 lifetime 600
crypto isakmp profile ISAKMPP
   keyring KEYS
   match identity address 0.0.0.0
crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac
 mode tunnel
crypto ipsec profile IPSECPP
 set transform-set TS
 set isakmp-profile ISAKMPP
interface loopback 1000
  ip address 10.1.0.1 255.255.255.0
interface tunnel 1000
  ip address 80.1.0.1 255.255.255.0
  tunnel source loopback 1000
  tunnel mode ipsec ipv4
  tunnel destination 10.2.0.1
  tunnel protection ipsec profile IPSECPP
interface loopback 1001
  ip address 10.1.1.1 255.255.255.0
interface tunnel 1001
  ip address 80.1.1.1 255.255.255.0
  tunnel source loopback 1001
  tunnel mode ipsec ipv4
  tunnel destination 10.2.1.1
  tunnel protection ipsec profile IPSECPP
end
###################################
###################################
# config for Cisco Router B:
configure terminal
interface GigabitEthernet0/0/0.880
  ip address 192.168.1.2 255.255.255.0
crypto keyring KEYS
  pre-shared-key address 0.0.0.0 0.0.0.0 key cisco
crypto isakmp policy 10
 encr 3des
 hash sha256
 authentication pre-share
 group 2
 lifetime 600
crypto isakmp profile ISAKMPP
   keyring KEYS
   match identity address 0.0.0.0
crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac
 mode tunnel
crypto ipsec profile IPSECPP
 set transform-set TS
 set isakmp-profile ISAKMPP
interface loopback 1000
  ip address 10.2.0.1 255.255.255.0
interface tunnel 1000
  ip address 80.1.0.1 255.255.255.0
  tunnel source loopback 1000
  tunnel mode ipsec ipv4
  tunnel destination 10.1.0.1
  tunnel protection ipsec profile IPSECPP
interface loopback 1001
  ip address 10.2.1.1 255.255.255.0
interface tunnel 1001
  ip address 80.1.1.1 255.255.255.0
  tunnel source loopback 1001
  tunnel mode ipsec ipv4
  tunnel destination 10.1.1.1
  tunnel protection ipsec profile IPSECPP
end
###################################
###################################
# unconfig for Cisco Router A and B:
configure terminal
no interface tunnel 1000
no interface loopback 1000
no interface tunnel 1001
no interface loopback 1001
no crypto ipsec profile IPSECPP
no crypto isakmp profile ISAKMPP
no crypto keyring KEYS
no crypto isakmp policy 10
no crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac
end



【信息科学与工程学】【数据中心】 第七篇 智算中心CLOS组网整体设计 区域主要功能网络要求技术选型安全等级可用性要求训练区​大规模AI模型训练,分布式计算超高带宽(100G+),超低延迟(<1ms),无损网络RoCEv2,PFC,DCQCN,多路径P4(最高)99.99%推理区​实时AI推理,模型服务低延迟(<10ms),高可用,弹性扩展智能负载均衡,服务网格,容器网络P3(高)99.999%公共服务区​统一认证,API网关,数据服务多租户隔离,安全防护,弹性带宽VXLAN,EVPN,微隔离P3(高)99.99%存储区​高性能存储,数据湖超高带宽,低延迟,高IOPSNVMe- 阅读详情

相关推荐

【信息科学与工程学】【通信工程】第五十九篇 IP网络设计01

IP网络设计不是只写ip address;它本质是的问题,所以参数天然分布在:层级例子物理/传输(可选但你会要求光路/电路)光功率/OSNR/色散/衰减/BER/FEC;铜/微波链路预算L1/L2 链路模型速率、MTU、成帧开销、串行化、传播时延、缓冲排队/调度/QoS服务曲线、令牌桶、延迟界、丢包概率近似路由/TE/可靠性流守恒、路径容量、切换/收敛时间信息论/可达性Shannon 上限、FEC 有效码率、链路容量 after overhead计算科学/数值。

weixin_49199313的博客 511

Scale IPSec config over cisco router

Cisco Router 的IPSec配置很复杂,如果需要生成多条tunnel的配置的时候,需要很大的工作量 简单写了一个脚本来生成,看看结果如何把 Limitation: 1. 支持IKEv2 2. 只能在Cisco IOS router上运行 3. Topology: site to site Benifit: 同时生成A和B两个router的配置,赞吧?

跳着Samba的狮子 743

【Cadence】 ADS Dynamic Link使用教程

在Cadence617上使用ADS Dynamic Link

乾巽的博客 6074

Telnet: Error opening terminal: network

Python telnet Error opening terminal: network ansi xterm

跳着Samba的狮子 1409

【深度学习】手把手教你在远程服务器上跑 YOLOv3 相关代码(含环境配置)

这篇文章主要记录了如何配置项目环境以及如何在远程服务器上跑 YOLOv3 模型。

作者正在煮茶中... 2383

一种高超声速飞行器弹道的仿真方法

设计并实现了一个高超声速飞行器弹道仿真算法,并应用到基于OSGEarth的态势中。

eyepeak的博客 6542

python获取当前日期前后N天或N月的日期

<br />#!/usr/bin/python ''' Filename: "utildate.py" author: "zhangsong" date : "2009-03-24" version: "1.00" ''' from time import strftime, localtime from datetime import timedelta, date import calendar year = strftime("%Y",localtime()) mo

跳着Samba的狮子 1378

Python实战:从中国气象局天擎平台自动化获取与处理雷达基数据

本文详细介绍了如何利用Python脚本实现从中国气象局天擎平台自动化获取与处理雷达基数据。通过环境搭建、安全认证、核心代码编写及工程化优化,构建了一个包含自动查询、批量下载、错误重试和格式转换的完整数据管道,旨在帮助气象水文领域的研究者与数据分析师从繁琐的手动操作中解放出来,高效管理海量数据。

ipfs8storage的博客 919

python字符串操作(连接、比较、格式化等)

<br /> <!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;}

跳着Samba的狮子 814

泛微OA表单开发实战:如何用JavaScript动态控制明细表的必填与可编辑属性

本文详细介绍了如何在泛微OA系统中使用JavaScript动态控制明细表字段的必填与可编辑属性。通过主表字段变更事件监听和明细表字段属性批量修改,实现智能化的表单交互,提升用户体验和系统灵活性。文章深入解析了关键API的使用方法,并提供了实战代码示例和最佳实践。

weixin_30955617的博客 548

AIAgent知识表示与推理:基于本体论与规则引擎的实现

AIAgent知识表示与推理:基于本体论与规则引擎的实现 1. 背景介绍 人工智能(AI)系统的核心是知识表示和推理,这是实现智能行为的基础。在过去的几十年里,人工智能领域一直致力于研究如何有效地表示和推理知识,以支持智能系统的决策和行为。其中,基于本体论的知识表示和

AI天才研究院 1493

AI全栈实战 | 3.9-01 爬虫入门:requests 加 BeautifulSoup 三分钟跑通,但 90% 的人栽在这 4 个“礼貌“问题上

⚠️:本文内容仅用于。请遵守目标站点的服务条款与相关法律法规,不得对目标服务造成负担,不得采集、传播个人隐私数据。技术是中性的,边界在你手里。爬虫的入门技术(requests 发请求 + BeautifulSoup 解析)三分钟就能学会。真正区分"会用爬虫"和"会做爬虫的人"的,是这篇我们跑通"请求→解析→存储"的最小闭环,然后重点把"合规与礼貌"这根弦给你绷上。

源码获取 | 运行部署 | 定制二开修改,如果回复不及时请耐心等待,请见谅。 403

【原创,解决CLodop安装后无法调用的问题】已经安装过CLodop,但是网页上仍然提示“clodop云打印服务(localhost本地)未安装启动,点击这里执行安装....”

在某些国内web网站中,需要安装一个名为“CLodop”的插件;但在实际使用过程中,即使安装了CLodop插件,网页试图调用它时还是会提示“clodop云打印服务(localhost本地)未安装启动,点击这里执行安装...”,且无法完成相关打印任务 本文属原创博客,分析了解决CLodop无法被调用的问题,并附上了原理和解决方法,本质上是和跨域请求以及CORS类安全组策略相关

link_in_csdn的博客 2万+

从一段视频到可漫游的 4D 有声场景:思路拆解与最小复现手记

只需一段手机视频,你就能生成可"走进去"的 4D 有声场景:转头时狗叫声方向随之变化,走近时声音更清晰。本文拆解 Video-to-4DAVScene 的核心思路,手把手带你用几十行 Python 搭出最小管线,把视频中的运动物体变成带空间位置的声源,并附上三个真实踩坑的排障经验,代码可直接跑。🎧

helloagent的博客 232

【YOLOv12多模态融合改进】| TFAM:时序融合注意力模块 | 引入通道 - 空间双分支注意力机制,解决双模态特征融合中时序关联不足的问题

TFAM模块通过时序信息驱动的注意力机制,解决了双时相特征融合中时序关联不足的问题,实现了更精准的变化区域定位和特征表示。其结构轻量、泛化性强,为变化检测任务提供了一种高效的特征融合解决方案。

Limiiiing的博客 866

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

【每天一个 Python 小案例30】Python 基础知识综合小项目:我的工具盒

作为系列收官,本篇把前 29 篇的知识点合成一个能直接用的命令行工具"我的工具盒":计算器(用 ast 解析表达式,不碰 eval)、单位换算与温度转换(一张换算表 + 特例分支)、记账与分类统计(Decimal + JSON 持久化)、以及用"字典当命令表"把菜单和业务逻辑解耦的主循环。文中对比了 eval 的安全隐患与 ast 白名单的做法,解释了 lambda 闭包在字典里的写法与晚绑定陷阱,并在最后给出整个系列的知识地图,把变量、数据结构、控制流、函数、类、异常、文件、标准库八块内容对应到具体篇目。

xinjiyaya的博客 424

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Python+Agent入门笔记(二):列表推导式、模块和异常,这些写 Agent 前得会

接上一篇《Python+Agent入门笔记(一)》。基础语法跑通之后,这篇聊几块日常写脚本绕不开的东西。还是按 JS/Go 开发者的视角写,尽量记录我实际卡过的地方。

qq_41241612的博客 430

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

详解Python条件语句

在 Python 中,if...else 是一种条件语句,可以根据给定的条件执行不同的操作。这个语句通常用于控制程序的流程。

2601_96798737的博客 205

Python3 协程:异步编程的核心机制与实战

协程是解决I/O密集型任务等待瓶颈的高效机制,相比线程更轻量、无锁开销。从yield到async/await的演进,使异步编程语义清晰、易于理解。通过async/await可实现并发执行多个任务(如gather、create_task),显著提升网络请求、爬虫等场景性能。关键在于使用异步库(如aiohttp)替代同步库,避免阻塞事件循环。合理控制超时与并发数,才能发挥协程最大优势。

Lxn2zh的博客 159

python如何控制浏览器

Python 可以通过 Selenium、Playwright 等工具实现浏览器自动化,从打开网页到执行复杂交互操作均可脚本化完成。Selenium生态成熟

2601_96797912的博客 76

二进制木马免杀-Python 分离免杀与 Web 挂马

二进制木马免杀-Python 分离免杀与 Web 挂马

2503_94637398的博客 268

torch.compile 差异仅 1e-6,边界样本预测为何翻转

torch.compile 加速后输出与 eager 不一致,部分预测翻转。逐层对比与 graph break 分析定位到动态分支翻转根因。容差回归仅适用于无分支翻转场景,零容忍场景应禁用编译。

昨日种种,皆成今我。今日种种,皆成新我。 159

Python 100讲课程导航:第08篇《Python input 与类型转换:构建可靠的交互程序》

本文详解Python中input()的返回类型为字符串,强调必须通过int()、float()等函数进行类型转换。重点讲解了输入验证的重要性,结合try-except处理ValueError等异常,实现可靠的交互程序。通过购物预算计算器实战,演示如何防范非法输入、处理边界值,并推荐使用Decimal避免浮点精度问题,提升程序健壮性。

铭渊老黄 134

【Python】国家中小学智慧教育平台电子教材批量下载与 PDF 合成实战

成果:两本语文电子课本(一年级上册 118 页 / 23MB、三年级上册 130 页 / 30.3MB),合计 248 页、约 54MB,单本下载加合成 40~60 秒,PDF 页数校验全部通过。经验教训SPA 站点的数据接口优先从 bundle 里挖,比抓页面稳得多;资源链接要按 private/public 分组看待,只取平台公开部分;页数、目录名这类“可推断”的信息,永远用实际响应验证一次;受限环境里“能不能跑浏览器”要在方案定稿前确认。后续计划:这版 PDF 是图片版,没有文字层;

木头大左的博客 133

魔塔社区微调训练Qwen2-1.5B-Instruct模型并烧录到‌RK3568开发板教程

本文基于Ubuntu 22.04 + CUDA 13.0.3环境,使用LLaMA-Factory框架对Qwen2-1.5B-Instruct模型进行LoRA微调,训练儿童故事生成专用模型。通过配置qwen模板、制作alpaca格式数据集、执行sft训练并合并LoRA权重,最终将模型转换为GGUF格式,并量化为Q4_K_M以适配RK3568嵌入式平台。全程支持国产镜像加速下载与显存优化,实现高效轻量化部署。

浅清秋慕夏的博客 185
上一篇: Scale IPSec config over cisco router
下一篇: CSR1000v XML file over KVM
wunderup
博客等级 码龄20年 13粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值