github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/services/wireguard/connection/dns/dns_windows.go (about) 1 /* 2 * Copyright (C) 2020 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package dns 19 20 import ( 21 "fmt" 22 "os/exec" 23 ) 24 25 func setDNS(cfg Config) error { 26 cmd := fmt.Sprintf("netsh interface ipv4 set dnsservers name=%s source=static address=%s validate=no", cfg.IfaceName, cfg.DNS[0]) 27 out, err := exec.Command("powershell", "-Command", cmd).CombinedOutput() 28 if err != nil { 29 return fmt.Errorf("could not configure DNS, %s:%v", string(out), err) 30 } 31 return nil 32 } 33 34 func cleanDNS(cfg Config) error { 35 cmd := fmt.Sprintf("netsh interface ipv4 set dnsservers name=%s source=static address=none validate=no register=both", cfg.IfaceName) 36 out, err := exec.Command("powershell", "-Command", cmd).CombinedOutput() 37 if err != nil { 38 return fmt.Errorf("could not clean DNS, %s:%w", string(out), err) 39 } 40 return nil 41 }