本文实例讲述了python实现ipsec开权限的方法。分享给大家供大家参考。具体实现方法如下:7 `' d! d. s* k& K! x
windows自带的命令行工具netsh ipsec static add filter不支持批量添加,还会添加重复的规则进去。我用python编写了ipsecset解决了上述问题,支持批量添加,同一个列表里避免重复的规则。
! s6 R+ Z* r% _$ S! g0 B3 L4 f8 \为了方便使用,已编译成exe,源码和程序在下面的链接里
( o3 Z7 S) J6 h H9 A \3 c语法:* w' u! ?. f) v9 {+ \! H W
参数和netsh ipsec static add filter的参数是一样的,不区分大小写8 v# P/ k( g b
必要参数:* A5 I( k' @% u% R6 ^% I! v8 v5 k
srcaddr=(me/any/特定ip/网段)
7 V6 |: `3 u+ c; g% bdstaddr=(me/any/特定ip/网段)
2 H' D1 c* w' o+ j" a: S( vdstport=(0/特定端口)
1 j% p/ _, @& N1 w: Q5 P默认参数:
) V& a2 X! k9 osrcport=0( ? T9 g, Y# V/ u! M
srcmask=255.255.255.255
; |; V4 }, Y9 s% O3 \* vdstmask=255.255.255.255
/ ~3 `+ A9 Q0 [; @/ _: ?) T/ i4 z2 Wprotocol=tcp
" Q/ m6 b- }7 _8 D4 n1 W# H1 y# s tmirrored=yes$ L0 j1 I7 U& T! R3 r! ~
filterlist=选用规则
3 U t3 w. e/ [0 Z! ^9 Wdescription=add by script {time_now}/ e, p4 ~/ u% K! f
批量操作:$ x$ ^9 M' v0 N0 H) I
“-和,两种操作符,可混合使用
# }6 h5 I7 C7 v! P" K# k支持批量操作的参数:srcport,dstport,srcaddr,dstaddr# t2 L# n7 e% i2 {1 X9 X# l
其中srcaddr和dstaddr仅最后一个段支持2 @6 J5 U1 P7 T
列如,srcport=1000-1003,1007,10094 c( |( \1 E+ x! c# {
srcaddr=1.1.1.10-13,15
% Q5 n7 Q* @, f4 \0 d' R示例如下:
; H0 E* [! c/ `1 n复制代码 代码如下:ipsecset srcport=1.1.1.1 dstport=2.2.2.2-30,31 dstport=8080 filterlist=基础规则
+ L( G( {8 A; x" m) B8 } I7 Dipsecset srcport=me dstport=any dstport=81-85,87
2 B, q7 C9 n6 G" |ipsecset srcport=me dstport=10.1.1.0 dstmask=255.255.255.0 dstport=6161 protocol=udp) H2 F* r* S3 C+ V' t6 b |
代码保存在github上
4 A1 M/ x- X+ J编译后的文件保存在dist文件夹
% O" X0 l0 l" X* L
: o8 r& ?# F) j更多网页制作信息请查看: 网页制作 |
|