feat(config): 添加 JSON/TOML 配置读取与 YAML/JSON/TOML 导出功能, 优化部分内部代码结构, 更新 Makefile:添加 Zig 外链检测、可选 UPX 压缩、构建流程优化
This commit is contained in:
@@ -10,16 +10,8 @@ import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
type NetIfWrap struct {
|
||||
net.Interface
|
||||
}
|
||||
|
||||
func (n NetIfWrap) GetName() string {
|
||||
return n.Interface.Name
|
||||
}
|
||||
|
||||
// 选择网卡
|
||||
func ChooseNic(nics []NetIfWrap, message string) (NetIfWrap, error) {
|
||||
func ChooseNic(nics []net.Interface, message string) (net.Interface, error) {
|
||||
var names []string
|
||||
for _, nic := range nics {
|
||||
names = append(names, nic.Name)
|
||||
@@ -30,18 +22,18 @@ func ChooseNic(nics []NetIfWrap, message string) (NetIfWrap, error) {
|
||||
Options: names,
|
||||
}, &choice)
|
||||
if err != nil {
|
||||
return NetIfWrap{}, err
|
||||
return net.Interface{}, err
|
||||
}
|
||||
for _, nic := range nics {
|
||||
if nic.Name == choice {
|
||||
return nic, nil
|
||||
}
|
||||
}
|
||||
return NetIfWrap{}, fmt.Errorf("未找到网卡: %s", choice)
|
||||
return net.Interface{}, fmt.Errorf("未找到网卡: %s", choice)
|
||||
}
|
||||
|
||||
// 设置静态IP
|
||||
func SetStaticIP(nic NetIfWrap, addr, mask, gateway string) error {
|
||||
func SetStaticIP(nic net.Interface, addr, mask, gateway string) error {
|
||||
cmd := exec.Command("netsh", "interface", "ip", "set", "address",
|
||||
fmt.Sprintf("name=%s", nic.Name),
|
||||
"static", addr, mask, gateway)
|
||||
@@ -53,7 +45,7 @@ func SetStaticIP(nic NetIfWrap, addr, mask, gateway string) error {
|
||||
}
|
||||
|
||||
// 设置 DHCP
|
||||
func SetDHCP(nic NetIfWrap) error {
|
||||
func SetDHCP(nic net.Interface) error {
|
||||
cmd := exec.Command("netsh", "interface", "ip", "set", "address",
|
||||
fmt.Sprintf("name=%s", nic.Name), "dhcp")
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
Reference in New Issue
Block a user