本文实例讲述了python实现ipsec开权限的方法。分享给大家供大家参考。具体实现方法如下:
windows自带的命令行工具netsh ipsec static add filter不支持批量添加,还会添加重复的规则进去。我用python编写了ipsecset解决了上述问题,支持批量添加,同一个列表里避免重复的规则。
为了方便使用,已编译成exe,源码和程序在下面的链接里
语法:
参数和netsh ipsec static add filter的参数是一样的,不区分大小写
必要参数:
srcaddr=(me/any/特定ip/网段)
dstaddr=(me/any/特定ip/网段)
dstport=(0/特定端口)
默认参数:
srcport=0
srcmask=255.255.255.255
dstmask=255.255.255.255
protocol=TCP
mirrored=YES
filterlist="选用规则"
description="add by script {time_now}"
批量操作:
“-"和","两种操作符,可混合使用
支持批量操作的参数:srcport,dstport,srcaddr,dstaddr
其中srcaddr和dstaddr仅最后一个段支持
列如,srcport=1000-1003,1007,1009
srcaddr=1.1.1.10-13,15
示例如下:
ipsecset srcport=me dstport=any dstport=81-85,87
ipsecset srcport=me dstport=10.1.1.0 dstmask=255.255.255.0 dstport=6161 protocol=udp
代码保存在github上 https://github.com/fmnisme/ipsecset
编译后的文件保存在dist文件夹
或者点击此处本站下载。
希望本文所述对大家的python程序设计有所帮助。

Pythonusesahybridmodelofcompilationandinterpretation:1)ThePythoninterpretercompilessourcecodeintoplatform-independentbytecode.2)ThePythonVirtualMachine(PVM)thenexecutesthisbytecode,balancingeaseofusewithperformance.

Pythonisbothinterpretedandcompiled.1)It'scompiledtobytecodeforportabilityacrossplatforms.2)Thebytecodeistheninterpreted,allowingfordynamictypingandrapiddevelopment,thoughitmaybeslowerthanfullycompiledlanguages.

Forloopsareidealwhenyouknowthenumberofiterationsinadvance,whilewhileloopsarebetterforsituationswhereyouneedtoloopuntilaconditionismet.Forloopsaremoreefficientandreadable,suitableforiteratingoversequences,whereaswhileloopsoffermorecontrolandareusefulf

Forloopsareusedwhenthenumberofiterationsisknowninadvance,whilewhileloopsareusedwhentheiterationsdependonacondition.1)Forloopsareidealforiteratingoversequenceslikelistsorarrays.2)Whileloopsaresuitableforscenarioswheretheloopcontinuesuntilaspecificcond

Pythonisnotpurelyinterpreted;itusesahybridapproachofbytecodecompilationandruntimeinterpretation.1)Pythoncompilessourcecodeintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).2)Thisprocessallowsforrapiddevelopmentbutcanimpactperformance,req

ToconcatenatelistsinPythonwiththesameelements,use:1)the operatortokeepduplicates,2)asettoremoveduplicates,or3)listcomprehensionforcontroloverduplicates,eachmethodhasdifferentperformanceandorderimplications.

Pythonisaninterpretedlanguage,offeringeaseofuseandflexibilitybutfacingperformancelimitationsincriticalapplications.1)InterpretedlanguageslikePythonexecuteline-by-line,allowingimmediatefeedbackandrapidprototyping.2)CompiledlanguageslikeC/C transformt

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools
