2026-01-24 23:40:22 +01:00
<!DOCTYPE html>
<!-- retoor <retoor@molodetz.nl> -->
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title > dns - Wren-CLI Manual</ title >
< link rel = "stylesheet" href = "../css/style.css" >
</ head >
< body >
< button class = "mobile-menu-toggle" > Menu</ button >
< div class = "container" >
< aside class = "sidebar" >
< div class = "sidebar-header" >
< h1 >< a href = "../index.html" > Wren-CLI</ a ></ h1 >
< div class = "version" > v0.4.0</ div >
</ div >
< nav class = "sidebar-nav" >
< div class = "section" >
< span class = "section-title" > Getting Started</ span >
< ul >
< li >< a href = "../getting-started/index.html" > Overview</ a ></ li >
< li >< a href = "../getting-started/installation.html" > Installation</ a ></ li >
< li >< a href = "../getting-started/first-script.html" > First Script</ a ></ li >
< li >< a href = "../getting-started/repl.html" > Using the REPL</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > Language</ span >
< ul >
< li >< a href = "../language/index.html" > Syntax Overview</ a ></ li >
< li >< a href = "../language/classes.html" > Classes</ a ></ li >
< li >< a href = "../language/methods.html" > Methods</ a ></ li >
< li >< a href = "../language/control-flow.html" > Control Flow</ a ></ li >
< li >< a href = "../language/fibers.html" > Fibers</ a ></ li >
< li >< a href = "../language/modules.html" > Modules</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > API Reference</ span >
< ul >
< li >< a href = "index.html" > Overview</ a ></ li >
2026-01-25 04:58:39 +01:00
< li >< a href = "string.html" > String</ a ></ li >
< li >< a href = "number.html" > Num</ a ></ li >
2026-01-24 23:40:22 +01:00
< li >< a href = "http.html" > http</ a ></ li >
< li >< a href = "websocket.html" > websocket</ a ></ li >
< li >< a href = "tls.html" > tls</ a ></ li >
< li >< a href = "net.html" > net</ a ></ li >
< li >< a href = "dns.html" class = "active" > dns</ a ></ li >
< li >< a href = "json.html" > json</ a ></ li >
< li >< a href = "base64.html" > base64</ a ></ li >
< li >< a href = "regex.html" > regex</ a ></ li >
< li >< a href = "jinja.html" > jinja</ a ></ li >
< li >< a href = "crypto.html" > crypto</ a ></ li >
< li >< a href = "os.html" > os</ a ></ li >
< li >< a href = "env.html" > env</ a ></ li >
< li >< a href = "signal.html" > signal</ a ></ li >
< li >< a href = "subprocess.html" > subprocess</ a ></ li >
< li >< a href = "sqlite.html" > sqlite</ a ></ li >
< li >< a href = "datetime.html" > datetime</ a ></ li >
< li >< a href = "timer.html" > timer</ a ></ li >
< li >< a href = "io.html" > io</ a ></ li >
2026-01-25 04:58:39 +01:00
< li >< a href = "pathlib.html" > pathlib</ a ></ li >
2026-01-24 23:40:22 +01:00
< li >< a href = "scheduler.html" > scheduler</ a ></ li >
< li >< a href = "math.html" > math</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > Tutorials</ span >
< ul >
< li >< a href = "../tutorials/index.html" > Tutorial List</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > How-To Guides</ span >
< ul >
< li >< a href = "../howto/index.html" > How-To List</ a ></ li >
</ ul >
</ div >
</ nav >
</ aside >
< main class = "content" >
< nav class = "breadcrumb" >
< a href = "../index.html" > Home</ a >
< span class = "separator" > /</ span >
< a href = "index.html" > API Reference</ a >
< span class = "separator" > /</ span >
< span > dns</ span >
</ nav >
< article >
< h1 > dns</ h1 >
< p > The < code > dns</ code > module provides DNS resolution functionality for looking up hostnames and resolving them to IP addresses.</ p >
< pre >< code > import "dns" for Dns</ code ></ pre >
< h2 > Dns Class</ h2 >
< div class = "class-header" >
< h3 > Dns</ h3 >
< p > DNS resolution utilities</ p >
</ div >
< h3 > Static Methods</ h3 >
< div class = "method-signature" >
< span class = "method-name" > Dns.lookup</ span > (< span class = "param" > hostname</ span > ) → < span class = "type" > String</ span >
</ div >
< p > Resolves a hostname to an IP address. Uses the system's default address family preference.</ p >
< ul class = "param-list" >
< li >< span class = "param-name" > hostname</ span > < span class = "param-type" > (String)</ span > - Hostname to resolve</ li >
< li >< span class = "returns" > Returns:</ span > IP address as a string</ li >
</ ul >
< pre >< code > var ip = Dns.lookup("example.com")
System.print(ip) // 93.184.216.34</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > Dns.lookup</ span > (< span class = "param" > hostname</ span > , < span class = "param" > family</ span > ) → < span class = "type" > String</ span >
</ div >
< p > Resolves a hostname to an IP address with a specific address family.</ p >
< ul class = "param-list" >
< li >< span class = "param-name" > hostname</ span > < span class = "param-type" > (String)</ span > - Hostname to resolve</ li >
< li >< span class = "param-name" > family</ span > < span class = "param-type" > (Num)</ span > - Address family: 0 (any), 4 (IPv4), or 6 (IPv6)</ li >
< li >< span class = "returns" > Returns:</ span > IP address as a string</ li >
</ ul >
< pre >< code > var ipv4 = Dns.lookup("example.com", 4)
System.print(ipv4) // 93.184.216.34
var ipv6 = Dns.lookup("example.com", 6)
System.print(ipv6) // 2606:2800:220:1:248:1893:25c8:1946</ code ></ pre >
< h3 > Address Family Values</ h3 >
< table >
< tr >
< th > Value</ th >
< th > Description</ th >
</ tr >
< tr >
< td >< code > 0</ code ></ td >
< td > Any (system default, typically prefers IPv4)</ td >
</ tr >
< tr >
< td >< code > 4</ code ></ td >
< td > IPv4 only</ td >
</ tr >
< tr >
< td >< code > 6</ code ></ td >
< td > IPv6 only</ td >
</ tr >
</ table >
< h2 > Examples</ h2 >
< h3 > Basic DNS Lookup</ h3 >
< pre >< code > import "dns" for Dns
var domains = ["example.com", "google.com", "github.com"]
for (domain in domains) {
var ip = Dns.lookup(domain)
System.print("%(domain) -> %(ip)")
}</ code ></ pre >
< h3 > IPv4 vs IPv6</ h3 >
< pre >< code > import "dns" for Dns
var hostname = "google.com"
var ipv4 = Dns.lookup(hostname, 4)
System.print("IPv4: %(ipv4)")
var fiber = Fiber.new {
return Dns.lookup(hostname, 6)
}
var result = fiber.try()
if (fiber.error != null) {
System.print("IPv6: Not available")
} else {
System.print("IPv6: %(result)")
}</ code ></ pre >
< h3 > Using with Socket Connection</ h3 >
< pre >< code > import "dns" for Dns
import "net" for Socket
var hostname = "httpbin.org"
var ip = Dns.lookup(hostname, 4)
System.print("Connecting to %(hostname) (%(ip))")
var socket = Socket.connect(ip, 80)
socket.write("GET /ip HTTP/1.1\r\nHost: %(hostname)\r\nConnection: close\r\n\r\n")
var response = ""
while (true) {
var data = socket.read()
if (data == null) break
response = response + data
}
socket.close()
System.print(response)</ code ></ pre >
< h3 > Using with TLS Connection</ h3 >
< pre >< code > import "dns" for Dns
import "tls" for TlsSocket
var hostname = "example.com"
var ip = Dns.lookup(hostname, 4)
var socket = TlsSocket.connect(ip, 443, hostname)
socket.write("GET / HTTP/1.1\r\nHost: %(hostname)\r\nConnection: close\r\n\r\n")
var response = socket.read()
System.print(response)
socket.close()</ code ></ pre >
< h3 > Error Handling</ h3 >
< pre >< code > import "dns" for Dns
var fiber = Fiber.new {
return Dns.lookup("nonexistent.invalid.domain")
}
var result = fiber.try()
if (fiber.error != null) {
System.print("DNS lookup failed: %(fiber.error)")
} else {
System.print("Resolved to: %(result)")
}</ code ></ pre >
< div class = "admonition note" >
< div class = "admonition-title" > Note</ div >
< p > DNS lookups are asynchronous operations that use libuv's thread pool. The calling fiber will suspend until the lookup completes.</ p >
</ div >
< div class = "admonition warning" >
< div class = "admonition-title" > Warning</ div >
< p > The hostname must be a string. Passing a non-string value will abort the fiber with an error. Similarly, the family parameter must be 0, 4, or 6.</ p >
</ div >
</ article >
< footer class = "page-footer" >
< a href = "net.html" class = "prev" > net</ a >
< a href = "json.html" class = "next" > json</ a >
</ footer >
</ main >
</ div >
< script src = "../js/main.js" ></ script >
</ body >
</ html >