是否有用于解析绑定区域文件的 python 库?

发布于 2024-07-08 22:36:58 字数 93 浏览 6 评论 0 原文

是否有用于解析绑定区域文件的 python 库? 基本上有助于添加/删除区域和记录。 即使有人手动修改区域文件,这也需要起作用,因此每次都覆盖区域文件并不是解决方案。

Any python libs for parsing Bind zone files?
Basically something that will aid in adding/removing zones and records.
This needs to work even if someone modifies the zone file by hand so overwriting the zone files every time is not a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

画尸师 2024-07-15 22:36:58

easyzone 是 dnspython 上的一个很好的层

Zoner 提供了一个用于编辑区域文件的 Web 界面并使用 easyzone。

easyzone is a nice layer over dnspython

Zoner provides a web-interface for editing zone files and makes use of easyzone.

一百个冬季 2024-07-15 22:36:58

我无法将 bicop 用于此类经典区域文件:

    $TTL 86400
@   IN SOA ns1.first-ns.de. postmaster.robot.first-ns.de. (
    2006040800   ; serial
    14400        ; refresh
    1800         ; retry
    604800       ; expire
    86400 )      ; minimum

@

                    IN NS      ns1.first-ns.de.

我将查看 dnspython

I was unable to use bicop for classical zone files like these:

    $TTL 86400
@   IN SOA ns1.first-ns.de. postmaster.robot.first-ns.de. (
    2006040800   ; serial
    14400        ; refresh
    1800         ; retry
    604800       ; expire
    86400 )      ; minimum

@

                    IN NS      ns1.first-ns.de.

I will have a look at dnspython

撩发小公举 2024-07-15 22:36:58

请参阅上面有关 bicop 的答案。

顺便说一句,http://pypi.python.org/pypi 处的 Python 包索引是寻找 Python 包的好地方。

编辑:下面的内容可能对尝试简单解析的人仍然有帮助,但 bicop 显然是现有的解决方案。

如果有人手动修改了配置,并且您不想覆盖它,这是否意味着您希望从现有配置中插入/删除行,保持所有注释等完好无损? 这确实可以防止解析然后重新输出配置,但这也是积极的 - 您不需要完全解析文件来实现您的目标。

要添加记录,您可以尝试一种简单的方法,例如

# define zone_you_care_about and line_you_wish_to_insert first, then:
for line in bindfile.read():
    out.write(line + '\n')
    if ('zone "%s" in' % zone_you_care_about) in line:
        out.write(line_you_wish_to_insert)

类似的代码适用于删除行:

# define zone_you_care_about and relevant_text_to_remove, then:
for line in bindfile.read():
    if not relevant_text_to_remove in line:
        out.write(line + '\n')

您可以使用像这样的简单代码片段来达到您需要的程度。

See answer above about bicop.

As an aside, the Python Package Index at http://pypi.python.org/pypi is a great place to look for Python packages.

EDIT: The below may still be helpful to someone trying to figure out simple parsing, but bicop is apparently an existing solution.

If someone has modified the config by hand, and you don't want to overwrite it, does that imply that you wish to insert/remove lines from an existing config, leaving all comments etc intact? That does prevent parsing then re-outputting the config, but that's a positive as well -- you don't need to fully parse the file to accomplish your goal.

To add a record, you might try a simple approach like

# define zone_you_care_about and line_you_wish_to_insert first, then:
for line in bindfile.read():
    out.write(line + '\n')
    if ('zone "%s" in' % zone_you_care_about) in line:
        out.write(line_you_wish_to_insert)

Similar code works for removing a line:

# define zone_you_care_about and relevant_text_to_remove, then:
for line in bindfile.read():
    if not relevant_text_to_remove in line:
        out.write(line + '\n')

You may get as far as you need with simple snippets of code like this.

孤独岁月 2024-07-15 22:36:58

我知道这很旧,但我能找到的唯一有效的方法是 iscpy。 您可以进行 easy_install。

easy_install iscpy

然后在 python 中:

import iscpy
iscpy.ParseISCString(open('somefile.conf', 'r').read())

返回一个字典。

I know this is old but the only working one I could find is called iscpy. You can do an easy_install.

easy_install iscpy

Then in python:

import iscpy
iscpy.ParseISCString(open('somefile.conf', 'r').read())

Which returns a dictionary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文