How to send notification?

22 views
Skip to first unread message

Bino Oetomo

unread,
Nov 5, 2023, 3:03:26 AM11/5/23
to dnspython-users
Dear All.

I'm try to write a simple 'notify relay'.

For the start, it will query a SOA record from my test BIND9 server and send the result to dnspython based receiver.

I just made a small modification from https://groups.google.com/g/dnspython-users/c/hUM6ADAEZr8/m/YuvzSZmrCwAJ

here is my script
```
import dns.message
import dns.rdataclass
import dns.rdatatype
import dns.query
import dns.opcode
import dns.flags
import dns.resolver

master_dns = '192.168.56.106'

# Slave dns, copied from
# https://github.com/rthalley/dnspython/blob/master/examples/receive_notify.py

slave_dns_addr = '192.168.56.1'
slave_dns_port = 5001
chk_domain = 'computingforgeeks.local'


res = dns.resolver.make_resolver_at(master_dns)
answer = res.resolve(chk_domain, "SOA")
soaObj = answer[0]

notify = dns.message.make_query(chk_domain, dns.rdatatype.SOA)
notify.request_payload = soaObj
notify.set_opcode(dns.opcode.NOTIFY)
notify.flags -= dns.flags.RD


response = dns.query.udp(q=notify,
    where=slave_dns_addr,
    port=slave_dns_port,
    timeout=5)

print(f'RESPONSE: {response}')

```

I got traceback as :
```
Traceback (most recent call last):
  File "./query01.py", line 29, in <module>
    response = dns.query.udp(q=notify,
  File "/home/bino/Documents/pujo/playdns/venv/lib/python3.8/site-packages/dns/query.py", line 695, in udp
    wire = q.to_wire()
  File "/home/bino/Documents/pujo/playdns/venv/lib/python3.8/site-packages/dns/message.py", line 564, in to_wire
    if max_size < 512:
TypeError: '<' not supported between instances of 'SOA' and 'int'

```

Kindly please tell me how to properly send a SOA object to a DNS server.

Sincerely  
-bino-

Bob Halley

unread,
Nov 5, 2023, 8:12:07 AM11/5/23
to dnspython-users
You want to make the notify like this:

notify = dns.message.make_query(chk_domain, dns.rdatatype.SOA, flags=dns.flags.AA)
notify.set_opcode(dns.opcode.NOTIFY)
notify.answer.append(answer.rrset)

Your code was trying to set request_payload, which is an EDNS0 size parameter, when what you wanted to do was an an SOA RRset to the answer section.  Also, you were trying to add a single rdata instead of an RRset with one item.
Reply all
Reply to author
Forward
0 new messages