Files
flora-kit/flora/network_setup_win.go
0x1024 fcf771e160 v0.2.5
- windows 透明代理
2017-07-02 19:21:59 +08:00

48 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package flora
import (
"os/exec"
"log"
)
type windows struct {
address string
}
const (
cmdRegistry = `reg`
cmdRegistryAdd = `add`
internetSettingsKey = `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings`
keyProxyEnable = `ProxyEnable`
keyProxyServer = `ProxyServer`
dataTypeDWord = `REG_DWORD`
dataTypeRegSZ = `REG_SZ`
)
func (w *windows) TurnOnGlobProxy() {
c := exec.Command(cmdRegistry, cmdRegistryAdd, internetSettingsKey, `/v`, keyProxyEnable, `/t`, dataTypeDWord, `/d`, `1`, `/f`)
var err error
if _, err = c.CombinedOutput(); err != nil {
log.Printf("enable windows proxy has error %s", err)
}
c = exec.Command(cmdRegistry, cmdRegistryAdd, internetSettingsKey, `/v`, keyProxyServer, `/t`, dataTypeRegSZ, `/d`, w.address, `/f`)
if _, err = c.CombinedOutput(); err != nil {
log.Printf("Windows global proxy settings has error %s , Try to set it manually ", err)
}
if nil == err {
log.Print("Windows global proxy settings are successful Please use after 2 minutes ...")
}
}
// TurnOffSystemProxy
func (w *windows) TurnOffGlobProxy() {
var err error
c := exec.Command(cmdRegistry, cmdRegistryAdd, internetSettingsKey, `/v`, keyProxyEnable, `/t`, dataTypeDWord, `/d`, `0`, `/f`)
if _, err = c.CombinedOutput(); err != nil {
log.Printf("disable windows proxy has error %s", err)
}
if nil == err{
log.Print("disable windows proxy settings are successful ...")
}
}