The examples in this article describe how Python implements IPSec-open permissions. Share to everyone for your reference. The implementation method is as follows:
Windows comes with a command-line tool that netsh ipsec static add filter does not support bulk additions, and also adds duplicate rules in. I wrote Ipsecset in Python to solve the above problems, support batch additions, and avoid duplicate rules in the same list.
For ease of use, has been compiled into EXE, the source code and program in the following link
Grammar:
Parameters are the same as the parameters of the netsh ipsec static add filter, and are not case-sensitive
Necessary parameters:
Srcaddr= (me/any/specific ip/network segment)
Dstaddr= (me/any/specific ip/network segment)
dstport= (0/specific port)
Default parameters:
Srcport=0
srcmask=255.255.255.255
dstmask=255.255.255.255
Protocol=tcp
Mirrored=yes
filterlist= "Selection Rules"
description= "Add by script {Time_now}"
Bulk operations:
"-" and "," two types of operators that can be used in combination
Parameters to support bulk operations: SRCPORT,DSTPORT,SRCADDR,DSTADDR
where srcaddr and dstaddr only the last segment support
GCA, srcport=1000-1003,1007,1009
srcaddr=1.1.1.10-13,15
Examples are as follows:
Copy the Code code as follows:
Ipsecset srcport=1.1.1.1 dstport=2.2.2.2-30,31 dstport=8080 filterlist= "Basic Rules"
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
The code is saved on GitHub Https://github.com/fmnisme/ipsecset
The compiled file is saved in the Dist folder
or click here to download this site.
Hopefully this article will help you with Python programming.