forked from txthinking/brook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c747fd
commit 8b5e51e
Showing
4 changed files
with
163 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,53 @@ | ||
package sysproxy | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"os/exec" | ||
"regexp" | ||
) | ||
|
||
// GetNetworkInterfaces returns interface list | ||
func GetNetworkInterfaces() ([]string, error) { | ||
return []string{}, nil | ||
} | ||
|
||
func TurnOnSystemProxy(pac string) error { | ||
return nil | ||
} | ||
|
||
func TurnOffSystemProxy() error { | ||
return nil | ||
} | ||
|
||
// SetDNSServer used to set system DNS server | ||
func SetDNSServer(server string) error { | ||
f, err := os.OpenFile("/etc/resolv.conf", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
_, err = f.WriteString("nameserver " + server) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// GetDefaultGateway returns default gateway | ||
func GetDefaultGateway() (string, error) { | ||
c := exec.Command("ip", "route") | ||
out, err := c.CombinedOutput() | ||
if err != nil { | ||
return "", errors.New(string(out) + err.Error()) | ||
} | ||
r, err := regexp.Compile(`default.*?(\d+.\d+\.\d+\.\d+)`) | ||
if err != nil { | ||
return "", err | ||
} | ||
ss := r.FindStringSubmatch(string(out)) | ||
if len(ss) == 0 { | ||
return "", errors.New("Can not find default gateway") | ||
} | ||
return ss[1], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters