Skip to content

Commit ac978df

Browse files
committed
fix: populate dns_resolvers() on Windows via ipconfig
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent fe6972d commit ac978df

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

host/src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,32 @@ fn dns_resolvers() -> &'static HashSet<IpAddr> {
324324
}
325325
set
326326
}
327-
#[cfg(not(unix))]
327+
#[cfg(windows)]
328+
{
329+
let mut set = HashSet::new();
330+
if let Ok(output) = std::process::Command::new("ipconfig").arg("/all").output() {
331+
let text = String::from_utf8_lossy(&output.stdout);
332+
let mut in_dns_block = false;
333+
for line in text.lines() {
334+
let trimmed = line.trim();
335+
if let Some(rest) = trimmed.strip_prefix("DNS Servers") {
336+
in_dns_block = true;
337+
let value = rest.trim_start_matches(['.', ' ', ':']);
338+
if let Ok(ip) = value.parse::<IpAddr>() {
339+
set.insert(ip);
340+
}
341+
} else if in_dns_block {
342+
if let Ok(ip) = trimmed.parse::<IpAddr>() {
343+
set.insert(ip);
344+
} else {
345+
in_dns_block = false;
346+
}
347+
}
348+
}
349+
}
350+
set
351+
}
352+
#[cfg(not(any(unix, windows)))]
328353
{
329354
HashSet::new()
330355
}

0 commit comments

Comments
 (0)