Python implementation IPSec Open permissions instance

Source: Internet
Author: User
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.

  • 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.