Return the response to the query, trying UDP first and falling back to TCP if UDP results in a truncated response. *q*, a ``dns.message.Message``, the query to send *where*, a ``str`` containing an IPv4 or IPv6 address, where to send the message. *timeout*, a ``float`` or ``None`
(
q: dns.message.Message,
where: str,
timeout: float | None = None,
port: int = 53,
source: str | None = None,
source_port: int = 0,
ignore_unexpected: bool = False,
one_rr_per_rrset: bool = False,
ignore_trailing: bool = False,
udp_sock: Any | None = None,
tcp_sock: Any | None = None,
ignore_errors: bool = False,
)
| 989 | |
| 990 | |
| 991 | def udp_with_fallback( |
| 992 | q: dns.message.Message, |
| 993 | where: str, |
| 994 | timeout: float | None = None, |
| 995 | port: int = 53, |
| 996 | source: str | None = None, |
| 997 | source_port: int = 0, |
| 998 | ignore_unexpected: bool = False, |
| 999 | one_rr_per_rrset: bool = False, |
| 1000 | ignore_trailing: bool = False, |
| 1001 | udp_sock: Any | None = None, |
| 1002 | tcp_sock: Any | None = None, |
| 1003 | ignore_errors: bool = False, |
| 1004 | ) -> Tuple[dns.message.Message, bool]: |
| 1005 | """Return the response to the query, trying UDP first and falling back |
| 1006 | to TCP if UDP results in a truncated response. |
| 1007 | |
| 1008 | *q*, a ``dns.message.Message``, the query to send |
| 1009 | |
| 1010 | *where*, a ``str`` containing an IPv4 or IPv6 address, where to send the message. |
| 1011 | |
| 1012 | *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query |
| 1013 | times out. If ``None``, the default, wait forever. |
| 1014 | |
| 1015 | *port*, an ``int``, the port send the message to. The default is 53. |
| 1016 | |
| 1017 | *source*, a ``str`` containing an IPv4 or IPv6 address, specifying the source |
| 1018 | address. The default is the wildcard address. |
| 1019 | |
| 1020 | *source_port*, an ``int``, the port from which to send the message. The default is |
| 1021 | 0. |
| 1022 | |
| 1023 | *ignore_unexpected*, a ``bool``. If ``True``, ignore responses from unexpected |
| 1024 | sources. |
| 1025 | |
| 1026 | *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own RRset. |
| 1027 | |
| 1028 | *ignore_trailing*, a ``bool``. If ``True``, ignore trailing junk at end of the |
| 1029 | received message. |
| 1030 | |
| 1031 | *udp_sock*, a ``socket.socket``, or ``None``, the socket to use for the UDP query. |
| 1032 | If ``None``, the default, a socket is created. Note that if a socket is provided, |
| 1033 | it must be a nonblocking datagram socket, and the *source* and *source_port* are |
| 1034 | ignored for the UDP query. |
| 1035 | |
| 1036 | *tcp_sock*, a ``socket.socket``, or ``None``, the connected socket to use for the |
| 1037 | TCP query. If ``None``, the default, a socket is created. Note that if a socket is |
| 1038 | provided, it must be a nonblocking connected stream socket, and *where*, *source* |
| 1039 | and *source_port* are ignored for the TCP query. |
| 1040 | |
| 1041 | *ignore_errors*, a ``bool``. If various format errors or response mismatches occur |
| 1042 | while listening for UDP, ignore them and keep listening for a valid response. The |
| 1043 | default is ``False``. |
| 1044 | |
| 1045 | Returns a (``dns.message.Message``, tcp) tuple where tcp is ``True`` if and only if |
| 1046 | TCP was used. |
| 1047 | """ |
| 1048 | try: |