2

dhcpd.conf ファイルを解析する最良の方法はどのようなものですか?

ddns-update-style none;
authoritative;
option domain-name "example.org"
option domain-name-servers ns1.example.org, ns2.example.org


subnet 172.16.31.0 netmask 255.255.255.0 {
    # default gateway
    option routers 172.16.31.10;
    option subnet-mask 255.255.255.0;

    option domain-name "aaaaaa";
    option domain-name-servers 172.16.31.10;
    #option nis-domain "domain.org";

    range dynamic-bootp 172.16.31.80 172.16.31.90;
    default-lease-time 21600;
    max-lease-time 43200;

    host test {
        hardware ethernet 00:23:8b:42:3f:d1;
        fixed-address 172.16.31.3;
    }

}

私は iscpy モジュールを試しました:

a = iscpy.ParseISCString(open('dhcpd.conf', 'r').read())

そのモジュールは、オプションをキーとして、オプションの次の文字列を dict の値として辞書を作成します。ただし、オプションが次のようになっている場合はうまく機能しません。

option domain-name "example.org"
option domain-name-servers ns1.example.org, ns2.example.org

それは次のようになります。

{'option domain-name':'example.org', 'option domain-name-servers":'ns1.example.org, ns2.example.org'}

しかし、出力は次のとおりです。

{'option':'domain-name-servers: ns1.example.org, ns2.example.org'}

そのモジュールまたは他のモジュールでより良い方法はありますか? ありがとう

4

1 に答える 1

0

dhcpd.conf 「完全に」読むことをお勧めします。次に、各ディレクティブに従って、またはクラスなどのクラスを作成すると、データを解析できますdata structuredict

于 2013-10-06T18:21:49.787 に答える