engine/Networking/src/resolve.rs
2024-08-23 13:22:09 +02:00

15 lines
546 B
Rust

use std::net::*;
use trust_dns_resolver::config::*;
use trust_dns_resolver::Resolver;
pub fn resolve(url: &str) -> Vec<IpAddr> {
// Construct a new Resolver with default configuration options
let resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default()).unwrap();
// Lookup the IP addresses associated with a name.
let response = resolver.lookup_ip(url).unwrap();
// There can be many addresses associated with the name,
// this can return IPv4 and/or IPv6 addresses
response.iter().collect()
}