-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface_windows.go
75 lines (65 loc) · 1.33 KB
/
interface_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package l2
import (
"bytes"
"fmt"
"io/ioutil"
"os/exec"
"time"
"github.com/reusee/e5"
"github.com/songgao/water"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
func (n *Network) SetupInterface() {
interfaceType := water.DeviceType(water.TAP)
iface, err := water.New(water.Config{
DeviceType: interfaceType,
PlatformSpecificParams: water.PlatformSpecificParams{
ComponentID: "tap0901",
},
})
ce(err)
out, err := exec.Command(
"netsh",
"int",
"ip",
"set",
"address",
iface.Name(),
"static",
n.LocalNode.LanIP.String(),
"255.255.255.0",
"none",
"1",
).CombinedOutput()
ce.WithInfo("%s", fromGBK(out))(err)
out, err = exec.Command(
"netsh",
"int",
"ip",
"set",
"dns",
iface.Name(),
"static",
"127.0.0.1",
).CombinedOutput()
ce.WithInfo("%s", fromGBK(out))(err)
//TODO use consistent MAC
//TODO set MACs
out, err = exec.Command("netsh", "interface", "ipv4", "set", "subinterface",
iface.Name(),
fmt.Sprintf(`mtu=%d`, n.MTU),
"store=persistent",
).CombinedOutput()
ce.WithInfo("%s", fromGBK(out))(err)
time.Sleep(time.Second * 3)
n.iface = iface
}
func fromGBK(bs []byte) []byte {
r := transform.NewReader(bytes.NewReader(bs), simplifiedchinese.GBK.NewDecoder())
out, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
return out
}