python - PowerDNS 没有从管道后端得到答案

标签 python custom-backend

我正在尝试为 powerdns 编写自己的管道后端,但无法使其正常工作。我正在使用后端启动 pdn_server 并尝试使用命令测试它:

# nslookup example.com 127.0.0.1

# dig @127.0.0.1 example.com

第一个问题是对后端的第一个查询带有类型“SOA”(后端 abi 版本 2):

Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0

我想“好吧,让我们从 SOA 开始”并尝试编写部分代码。 在调试中,我可以看到后端已启动,确实收到了查询并将答案发送到 pdns。但似乎出了问题,pdns 没有得到它。无法弄清楚出了什么问题。源码及调试如下:

#!/usr/bin/python

from sys import stdin, stdout, stderr

data = stdin.readline()
stdout.write("OK\tCC DNS Backend\n")
stdout.flush()

stderr.write("$$$ Main loop started...\n")

while True:
    line = stdin.readline().strip()

    kind, qname, qclass, qtype, id, ip, mask = line.split('\t')

    if kind == 'Q':
        stderr.write('$$$ Got request ' + qname + '\n')
        if qtype != 'SOA':
            r = "DATA\t'+qname+'\t'+qtype+'\t'+qclass+'\t'+'127.0.0.1\n"
            stderr.write(r)
            stdout.write(r)
        else:
            stderr.write("$$$ Sending SOA\n")
            r = "DATA\texample.com\tIN\tSOA\t86400\t1\tahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600\n"
            stdout.write(r)
            stderr.write(r)

        stdout.write("END\n")
        stderr.write("END\n")

调试:

Dec 05 15:36:43 Done launching threads, ready to distribute questions
Dec 05 15:36:49 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END
$$$ Main loop started...
Dec 05 15:36:49 Backend launched with banner: OK    CC DNS Backend
$$$ Main loop started...
Dec 05 15:36:49 Backend launched with banner: OK    CC DNS Backend
Dec 05 15:36:54 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END
Dec 05 15:36:59 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END

最佳答案

问题出在 python 的缓冲输入输出中。 邮件列表用户给出了答案 - 更改行:

#!/usr/bin/python

#!/usr/bin/python -u

'-u'禁用缓冲。

关于python - PowerDNS 没有从管道后端得到答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20398994/

相关文章:

python 无法解码抑扬符

python - 如何用 django ORM 模仿 Python 集?

python - Tkinter 窗口显示(无响应)但代码正在运行

python - conn.set_listener() 中的第一个参数有何用途?

open-source - 用于开发应用程序后端的开源平台/软件

web-applications - 如何将对象传递给 FatFractal 服务器扩展、从扩展内部访问以及将对象返回给客户端应用程序?

javascript - 我可以在自己的服务器上托管 BaaS 解决方案吗?

python - 在 Python 中读取图像 XMP 数据