Python implements an ipsec permission opening instance and pythonipsec

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.