Sample code for 30+ languages & platforms
Rust

Resolve a Hostname to an IP Address

See more Socket/SSL/TLS Examples

Demonstrates Socket.DnsLookup, which resolves a hostname and returns one numeric IP address.

Background. A maxWaitMs of 0 waits indefinitely; a positive value bounds the wait. Resolved results may be served from Chilkat's process-wide DNS cache.

Chilkat Rust Downloads

Rust
let socket = chilkat::Socket::new();

// Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
let Ok(ip_address) = socket.dns_lookup("example.com", 5000) else {
    println!("{}", socket.last_error_text());
    return;
};

println!("Resolved IP address: {}", ip_address);