English:
Still learning Rust, I'm wanting to know how I could write to the host file on a Windows machine ("etc/hosts").
I've tried some methods from regular websites, but nothing has been helpful to me.
I haven't received any advice on Stackoverflow, so I would really appreciate any advice here.
Русский:
Все еще изучая Rust, я хочу знать, как я мог бы записать в файл хоста на компьютере с Windows ("etc/hosts").
Я пробовал некоторые методы с обычных веб-сайтов, но мне ничего не помогло.
Я не получал никаких советов по Stackoverflow, поэтому я был бы очень признателен за любой совет здесь.
Code I found / Код, который я нашел:
Still learning Rust, I'm wanting to know how I could write to the host file on a Windows machine ("etc/hosts").
I've tried some methods from regular websites, but nothing has been helpful to me.
I haven't received any advice on Stackoverflow, so I would really appreciate any advice here.
Русский:
Все еще изучая Rust, я хочу знать, как я мог бы записать в файл хоста на компьютере с Windows ("etc/hosts").
Я пробовал некоторые методы с обычных веб-сайтов, но мне ничего не помогло.
Я не получал никаких советов по Stackoverflow, поэтому я был бы очень признателен за любой совет здесь.
Code I found / Код, который я нашел:
Код:
const IPS: &[&str] = &["127.0.0.1", "google.com"];
let mut file = OpenOptions::new()
.write(true)
.append(true)
.open("C:\\Windows\\System32\\drivers\\etc\\hosts")
.unwrap();
for ip in IPS {
file.write_all(ip.as_bytes()).unwrap();
file.write_all(b"\n").unwrap();
}
file.sync_all().unwrap();