package dorkbox.netUtil import dorkbox.executor.Executor import java.io.BufferedWriter import java.io.File import java.io.FileWriter import java.io.IOException /** * */ object Dns { /** * @throws IOException if the DNS resolve.conf file cannot be read */ fun setDNSServers(dnsServersString: String) { if (Common.OS_LINUX) { val dnsServers = dnsServersString.split(","); val dnsFile = File("/etc/resolvconf/resolv.conf.d/head"); if (!dnsFile.canRead()) { throw IOException("Unable to initialize dns server file. Something is SERIOUSLY wrong"); } BufferedWriter(FileWriter(dnsFile)).use { it.write("# File location: /etc/resolvconf/resolv.conf.d/head\n"); it.write("# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)\n"); dnsServers.forEach { dns -> it.write("nameserver $dns\n"); } it.flush(); } Executor().command("resolvconf", "-u").startBlocking() } else { throw RuntimeException("NOT IMPL.") } } }