本文实例讲述了python实现ipsec开权限的方法。分享给大家供大家参考。具体实现方法如下:
" V8 k( l/ z; w) [# H. ]windows自带的命令行工具netsh ipsec static add filter不支持批量添加,还会添加重复的规则进去。我用python编写了ipsecset解决了上述问题,支持批量添加,同一个列表里避免重复的规则。
, o' M" ^3 G V% j6 v$ s# m; r. K为了方便使用,已编译成exe,源码和程序在下面的链接里! |! X; ^1 U6 o1 W! `3 J9 i D
语法:5 W8 h1 e& y& H, i) ~3 ]) @
参数和netsh ipsec static add filter的参数是一样的,不区分大小写
4 k% p0 @) w$ {& E$ f必要参数:- c) j" V+ e2 U0 R0 G$ h6 ?1 D
srcaddr=(me/any/特定ip/网段)& F# i4 Z5 Q9 h7 \
dstaddr=(me/any/特定ip/网段)% u9 f5 ]/ Q x' w
dstport=(0/特定端口) C1 o" M) ]( }
默认参数:
0 h8 D9 i/ O7 {srcport=06 ^, C0 J+ q# d6 O
srcmask=255.255.255.255
- g6 F3 i3 M( o2 U9 ndstmask=255.255.255.2557 i2 ~' X& x$ q
protocol=tcp/ h/ E# T' j" T; y8 f
mirrored=yes& Z7 S% [& j/ X D& M1 G' @6 W" }
filterlist=选用规则
* ~- p: t- c- L6 @$ ^& Kdescription=add by script {time_now}; J+ K- b9 M- M) t2 w0 v
批量操作:" m# t) ~$ d1 W1 v
“-和,两种操作符,可混合使用( O9 B P+ B& L# d
支持批量操作的参数:srcport,dstport,srcaddr,dstaddr8 H2 S' s9 J8 Z% s
其中srcaddr和dstaddr仅最后一个段支持1 m o: h2 F& n" @( w4 K
列如,srcport=1000-1003,1007,1009. o K2 X3 d3 V1 i( o- ~5 V
srcaddr=1.1.1.10-13,153 O2 \) M3 a$ j8 v3 G% V. u# `
示例如下:; |* m) g9 X1 F; D3 j; H+ |9 E5 Z
复制代码 代码如下:ipsecset srcport=1.1.1.1 dstport=2.2.2.2-30,31 dstport=8080 filterlist=基础规则
; g" j3 g5 v5 C0 V1 [$ o/ Ripsecset srcport=me dstport=any dstport=81-85,87! n$ [ t \/ U. n0 a& F
ipsecset srcport=me dstport=10.1.1.0 dstmask=255.255.255.0 dstport=6161 protocol=udp
6 g( x& U& |+ Z6 g, y& w代码保存在github上
* f" g. x/ j" O( X0 p4 O编译后的文件保存在dist文件夹
$ h9 p. }7 r8 Y# V0 E
( P6 g+ H0 G3 w' O9 u/ M' Q更多网页制作信息请查看: 网页制作 |
|