本文实例讲述了python实现ipsec开权限的方法。分享给大家供大家参考。具体实现方法如下:
5 I7 ^9 r: E, P" W+ ~6 Pwindows自带的命令行工具netsh ipsec static add filter不支持批量添加,还会添加重复的规则进去。我用python编写了ipsecset解决了上述问题,支持批量添加,同一个列表里避免重复的规则。
4 a3 b3 |. Y2 X) V4 V" h0 o为了方便使用,已编译成exe,源码和程序在下面的链接里, A& V* ], S4 q" j4 X1 A4 ] }
语法:% w3 k$ L- M: N, f
参数和netsh ipsec static add filter的参数是一样的,不区分大小写
% v8 [# _+ D5 d4 a- O必要参数:: d% e! y# Y, @/ {9 k) x& y
srcaddr=(me/any/特定ip/网段)
- X. u2 ~: e& ?* F0 W" V1 ^ Z* [dstaddr=(me/any/特定ip/网段)
! u2 r& Z2 ?/ z Mdstport=(0/特定端口)5 N4 {% P6 y5 e1 X1 S$ Z+ ]
默认参数:
, j& l" e% c1 f, r2 r# P& xsrcport=0
: L- W7 y- ]% a @srcmask=255.255.255.255# ~8 {4 c' ]3 N7 ^9 k# `$ s
dstmask=255.255.255.255; E1 P, |- A6 A9 \! o' @2 w$ e
protocol=tcp0 |# s& S" S6 _$ E* O w
mirrored=yes
9 i2 y4 N m8 R( lfilterlist=选用规则
( H' _" Z4 A5 a+ c0 \description=add by script {time_now}
" _0 i9 T4 D- i9 k- l# w批量操作:$ A2 Y4 P8 ]4 Q1 F: p
“-和,两种操作符,可混合使用# W. w" S+ W) P" [1 C9 I" x
支持批量操作的参数:srcport,dstport,srcaddr,dstaddr" C6 L* |9 g+ A3 B1 y9 X$ h/ t$ Z
其中srcaddr和dstaddr仅最后一个段支持4 V8 @0 o) N" F, w7 |7 D, Y: `
列如,srcport=1000-1003,1007,1009
% ]9 x. O+ u8 jsrcaddr=1.1.1.10-13,15* L, L* t7 E+ ^7 S! e
示例如下:
z! j4 M* R: ?8 \' Y4 {+ o6 @复制代码 代码如下:ipsecset srcport=1.1.1.1 dstport=2.2.2.2-30,31 dstport=8080 filterlist=基础规则2 D. ~* j1 ?2 `2 Y6 y' B7 b# b/ n" f
ipsecset srcport=me dstport=any dstport=81-85,87
( v4 Z, d. t/ M: e$ i8 u! hipsecset srcport=me dstport=10.1.1.0 dstmask=255.255.255.0 dstport=6161 protocol=udp1 s: q& B" D* d f: o' t9 C5 G
代码保存在github上
; H, \( _9 I* b- j4 M6 x编译后的文件保存在dist文件夹
* J5 g! `6 y: ?& [( ?/ e: v6 U8 n; P% C9 m$ L/ W8 E& ^# c6 B' U! @
更多网页制作信息请查看: 网页制作 |
|