.. image:: https://travis-ci.org/leforestier/ipsecparse.svg
:target: https://travis-ci.org/leforestier/ipsecparse
Parse and edit your ipsec configuration files (ipsec.conf)
Installation
~~~~~~~~~~~~
To install ipsecparse, simply:
.. code-block:: console
pip install ipsecparse
Examples
~~~~~~~~
.. code:: python
# 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
Raw data
{
"_id": null,
"home_page": "https://github.com/leforestier/ipsecparse",
"name": "ipsecparse",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "ipsec",
"author": "Benjamin Le Forestier",
"author_email": "benjamin@leforestier.org",
"download_url": "https://files.pythonhosted.org/packages/05/7d/24709be12867e3d202f82927db9879ebe4a9a20ef1b1c940bf95615ee1cf/ipsecparse-0.3.0.tar.gz",
"platform": "",
"description": ".. image:: https://travis-ci.org/leforestier/ipsecparse.svg\n :target: https://travis-ci.org/leforestier/ipsecparse\n\nParse and edit your ipsec configuration files (ipsec.conf)\n\nInstallation\n~~~~~~~~~~~~\n\nTo install ipsecparse, simply:\n\n.. code-block:: console\n\n pip install ipsecparse\n\nExamples\n~~~~~~~~\n\n.. code:: python\n\n # Load the configuration from a string.\n\n from ipsecparse import loads\n\n conf = loads(open('/etc/ipsec.conf').read())\n\n # The configuration is represented as a dictionnary\n # (actually a subclass of OrderedDict)\n\n # Each section of the configuration is an OrderedDict.\n\n # Let's modify some settings:\n\n conf['config', 'setup']['nat_traversal'] = 'yes'\n\n conf['conn', 'myconn']['left'] = '192.168.0.10'\n\n # Create a connection:\n\n conf['conn', 'mynewconn'] = {\n 'leftsubnet': '10.0.0.0/16',\n 'right': '192.168.0.1'\n }\n\n # You can also use an OrderedDict if order matters to you:\n\n from collections import OrderedDict\n\n conf['conn', 'mynewconn'] = OrderedDict(\n lefsubnet = '10.0.0.0/16',\n right = '192.168.0.1'\n )\n\n # Delete a connection:\n\n del conf['conn', 'mynewconn']\n\n # Same thing with certification authorities. Create a CA:\n\n conf['ca', 'myca'] = {\n 'cacert': 'MyCert.pem',\n 'crluri': 'http://crl.example.com/mycrl.crl',\n 'auto': 'add'\n }\n\n # Delete it:\n\n del conf['ca', 'myca']\n\n # Add an include:\n\n conf['include', '/etc/ipsec.d/ipsec.include'] = True\n\n # Delete it:\n\n del conf['include', '/etc/ipsec.d/ipsec.include']\n\n # Display the new configuration as a string:\n\n print(conf.dumps())\n\n # with four spaces indents instead of the default tabulations:\n\n print(conf.dumps(indent = ' '))\n\n # Replace the old configuration file:\n\n with open('/etc/ipsec.conf', 'w') as fd:\n fd.write(conf.dumps())\n\n # Search for connections inside the configuration.\n # Pass a callable to the `conn_filter` method.\n\n for name, section in conf.conn_filter(\n lambda conn: conn.get('leftsubnet') == '10.0.0.0/16'\n ):\n section['auto'] = 'start'\n\n # Or use the Key and Keys class\n # (just to make queries a bit shorter)\n\n from ipsecparse import Key, Keys\n\n for name, section in conf.conn_filter(\n Key('leftsubnet') == '10.0.0.0/16'\n ):\n section['auto'] = 'start'\n\n for name, section in conf.conn_filter(\n Keys('left', 'right').contains('192.168.0.1')\n ):\n del conf['conn', name]\n\n\nGitHub repo: https://github.com/leforestier/ipsecparse\n",
"bugtrack_url": null,
"license": "",
"summary": "Parse and edit your ipsec configuration files",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/leforestier/ipsecparse"
},
"split_keywords": [
"ipsec"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "057d24709be12867e3d202f82927db9879ebe4a9a20ef1b1c940bf95615ee1cf",
"md5": "b7ca8ce1748877812f7c0f9e2338d6a1",
"sha256": "d1d0daa2cda7c311d03817da8472b0ca5dddb26f52dfbba33bb6f9f676562433"
},
"downloads": -1,
"filename": "ipsecparse-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "b7ca8ce1748877812f7c0f9e2338d6a1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4579,
"upload_time": "2019-07-23T15:14:38",
"upload_time_iso_8601": "2019-07-23T15:14:38.351874Z",
"url": "https://files.pythonhosted.org/packages/05/7d/24709be12867e3d202f82927db9879ebe4a9a20ef1b1c940bf95615ee1cf/ipsecparse-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2019-07-23 15:14:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "leforestier",
"github_project": "ipsecparse",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"lcname": "ipsecparse"
}