Python implements an ipsec permission opening instance and pythonipsec
This example describes how to Enable ipsec access in python. Share it with you for your reference. The specific implementation method is as follows:
The command line tool netsh ipsec static add filter in windows does not support batch addition. Duplicate rules are also added. I wrote ipsecset in python to solve the above problem. It supports batch addition to avoid repeated rules in the same list.
For ease of use, compiled into exe, the source code and program are in the following link
Syntax:
The parameters are the same as those of netsh ipsec static add filter and are case insensitive.
Required parameters:
Srcaddr = (me/any/specific ip/CIDR Block)
Dstaddr = (me/any/specific ip/CIDR Block)
Dstport = (0/specific port)
Default parameters:
Srcport = 0
Srcmask = 255.255.255.255.255
Dstmask = 255.255.255.255.255
Protocol = TCP
Mirrored = YES
Filterlist = "select rules"
Description = "add by script {time_now }"
Batch operation:
"-" And "," can be used in combination
Parameters supporting batch operations: srcport, dstport, srcaddr, and dstaddr
Srcaddr and dstaddr are supported only in the last segment.
For example, srcport = 1000-1009
Srcaddr = 1.1.1.10-13,15
Example:
Copy codeThe Code is as follows: ipsecset srcport = 1.1.1.1 dstport = 2.2.2.2-30,31 dstport = 8080 filterlist = "basic rule"
Ipsecset srcport = me dstport = any dstport = 81-85,87
Ipsecset srcport = me dstport = 10.1.1.0 dstmask = 255.255.0 dstport = 6161 protocol = udp
Code saved on github https://github.com/fmnisme/ipsecset
The compiled files are saved in the dist folder.
Or click here to download.
I hope this article will help you with python programming.