Standard library
nox.dns
Explicit DNS resolution. nox.http resolves a host name by itself while connecting, so a program that validates the address first (SSRF protection) would otherwise resolve twice and could be
fooled by DNS rebinding. nox.dns.resolve makes the lookup a separate step; together with nox.http.request(..., connect_ip=...) the flow is resolve → validate → connect to the validated address.
import nox.dns
import nox.http
import nox.ip
ips: list[str] = nox.dns.resolve("api.example.com", 3000)
for ip in ips:
if nox.ip.is_global_text(ip): # see nox.ip
resp = nox.http.request("GET", "https://api.example.com/", "", {}, 5000, ip)
breakCapability: network.
| Function | Description |
|---|---|
resolve(host: str, timeout_ms: int = 0, doh_url: str = "") -> list[str] |
the A/AAAA addresses of host as text (at most 16, in the operating system's RFC 6724 order); doh_url is only used on WASM (see below) |
- IP literals (
203.0.113.7,[2001:db8::1]) andlocalhost/*.localhostcome back without touching the network. timeout_ms > 0bounds the lookup (DnsTimeoutError); with0it is bounded by a 2-minute cap. An unresolvable name raisesDnsError(the function never returns an empty list, so a caller cannot treat "failure" as "allowed").- Inside a fiber only the calling fiber waits. The lookup shares the bounded, single-flight resolver that
nox.httpuses. DnsCapabilityErrorwhen thenetworkcapability is denied;DnsErroron targets without a resolver (freestanding, and WASM unless adoh_urlis given).- Address classification (private/loopback/link-local/metadata ranges) is
nox.ip;nox.dnsonly resolves.
DNS on WASM (DNS-over-HTTPS)#
A browser or WASI module has no system resolver. On wasm32-freestanding --asyncify with the host fetch capability, pass the URL of a DoH JSON resolver (the application/dns-json format) as doh_url: the lookup is then two GET requests (?name=<host>&type=A and &type=AAAA) through the host's fetch.
ips: list[str] = nox.dns.resolve("api.example.com", 3000, "https://doh.example/dns-query")- There is no default resolver: the host names you look up are sent only to the server you choose. Without
doh_urlthe call raisesDnsError("not supported on this target"). - IP literals and
localhoststill need no network. A name with characters other than letters, digits,-,_and.is rejected without a request. DnsTimeoutErrorwhen the host'sfetchtimes out,DnsCapabilityErrorwhen the host grants no network capability,DnsErrorwhen neither query returns an address (NXDOMAIN or a malformed answer). One of the two queries returning addresses is a success.- The host's own network policy (
--net-allow,--allow-net) applies to the DoH server like any otherfetch. The addresses you get are only as trustworthy as that server: validate them withnox.ipbefore connecting.