Parse and edit your ipsec configuration files
Project description
Parse and edit your ipsec configuration files (ipsec.conf)
Examples
# Load the configuration from a string.
from ipsecparse import loads
conf = loads(open('/etc/ipsec.conf').read())
# The configuration is represented as a dictionnary
# (actually a subclass of OrderedDict)
# Each section of the configuration is an OrderedDict.
# Let's modify some settings:
conf['config', 'setup']['nat_traversal'] = 'yes'
conf['conn', 'myconn']['left'] = '192.168.0.10'
# Create a connection:
conf['conn', 'mynewconn'] = {
'leftsubnet': '10.0.0.0/16',
'right': '192.168.0.1'
}
# You can also use an OrderedDict if order matters to you:
from collections import OrderedDict
conf['conn', 'mynewconn'] = OrderedDict(
lefsubnet = '10.0.0.0/16',
right = '192.168.0.1'
)
# Delete a connection:
del conf['conn', 'mynewconn']
# Same thing with certification authorities. Create a CA:
conf['ca', 'myca'] = {
'cacert': 'MyCert.pem',
'crluri': 'http://crl.example.com/mycrl.crl',
'auto': 'add'
}
# Delete it:
del conf['ca', 'myca']
# Add an include:
conf['include', '/etc/ipsec.d/ipsec.include'] = True
# Delete it:
del conf['include', '/etc/ipsec.d/ipsec.include']
# Display the new configuration as a string:
print(conf.dumps())
# with four spaces indents instead of the default tabulations:
print(conf.dumps(indent = ' '))
# Replace the old configuration file:
with open('/etc/ipsec.conf', 'w') as fd:
fd.write(conf.dumps())
# Search for connections inside the configuration.
# Pass a callable to the `conn_filter` method.
for name, section in conf.conn_filter(
lambda conn: conn.get('leftsubnet') == '10.0.0.0/16'
):
section['auto'] = 'start'
# Or use the Key and Keys class
# (just to make queries a bit shorter)
from ipsecparse import Key, Keys
for name, section in conf.conn_filter(
Key('leftsubnet') == '10.0.0.0/16'
):
section['auto'] = 'start'
for name, section in conf.conn_filter(
Keys('left', 'right').contains('192.168.0.1')
):
del conf['conn', name]
GitHub repo: https://github.com/leforestier/ipsecparse
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
ipsecparse-0.0.1.zip
(7.0 kB
view details)
ipsecparse-0.0.1.tar.gz
(4.4 kB
view details)
File details
Details for the file ipsecparse-0.0.1.zip
.
File metadata
- Download URL: ipsecparse-0.0.1.zip
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 868ff0670f3ddbdf1117e6ae1780d83199d3c1d3efa6e29da97f72aaccf94b48 |
|
MD5 | 70e26291b1c430c7ca102af23fec3da1 |
|
BLAKE2b-256 | 628eded62f7f43042a4815270eb5015b14792d2564f538e27ceb69210e0187b2 |
File details
Details for the file ipsecparse-0.0.1.tar.gz
.
File metadata
- Download URL: ipsecparse-0.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f75fac9594593ca4420dd7b6d56e8abe6d4f924f2f723185a3794a5037aca9f1 |
|
MD5 | 419ae66c65111de70a5f3c973c5e464c |
|
BLAKE2b-256 | 14e55e9adb79524f31d355e150178706d3a411e1ef1745481ad9fef4a08cca1b |