Performs a DNS-SD (RFC6763) request :param service: the service name to query (e.g. _spotify-connect._tcp.local) :param af: the transport to use. socket.AF_INET or socket.AF_INET6 :param qtype: the type to use in the mDNS. Either TXT, PTR or SRV. :param iface: the interface to
(service="_services._dns-sd._udp.local",
af=socket.AF_INET,
qtype="PTR",
iface=None,
verbose=2,
timeout=3)
| 2003 | |
| 2004 | @conf.commands.register |
| 2005 | def dnssd(service="_services._dns-sd._udp.local", |
| 2006 | af=socket.AF_INET, |
| 2007 | qtype="PTR", |
| 2008 | iface=None, |
| 2009 | verbose=2, |
| 2010 | timeout=3): |
| 2011 | """ |
| 2012 | Performs a DNS-SD (RFC6763) request |
| 2013 | |
| 2014 | :param service: the service name to query (e.g. _spotify-connect._tcp.local) |
| 2015 | :param af: the transport to use. socket.AF_INET or socket.AF_INET6 |
| 2016 | :param qtype: the type to use in the mDNS. Either TXT, PTR or SRV. |
| 2017 | :param iface: the interface to do this discovery on. |
| 2018 | """ |
| 2019 | if af == socket.AF_INET: |
| 2020 | pkt = IP(dst=ScopedIP("224.0.0.251", iface), ttl=255) |
| 2021 | elif af == socket.AF_INET6: |
| 2022 | pkt = IPv6(dst=ScopedIP("ff02::fb", iface)) |
| 2023 | else: |
| 2024 | return |
| 2025 | pkt /= UDP(sport=5353, dport=5353) |
| 2026 | pkt /= DNS(rd=0, qd=[DNSQR(qname=service, qtype=qtype)]) |
| 2027 | ans, _ = sr(pkt, multi=True, timeout=timeout, verbose=verbose) |
| 2028 | return DNSSDResult(ans.res) |