fix: 网卡绑定问题
This commit is contained in:
@@ -2,6 +2,9 @@ package tools
|
||||
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -15,7 +18,24 @@ var httpTools map[string]*Http
|
||||
|
||||
func init() {
|
||||
if config.Settings.Basic.Interfaces == "" {
|
||||
HttpPack = genHttpPack(nil)
|
||||
var eth *Eth
|
||||
if flags.Interface != "" {
|
||||
netEth, err := net.InterfaceByName(flags.Interface)
|
||||
if err != nil {
|
||||
log.Warnf("获取指定网卡 %s 失败,使用默认网卡: %v", flags.Interface, err)
|
||||
} else {
|
||||
eth, err = ConvertInterface(*netEth)
|
||||
if err != nil {
|
||||
log.Warnf("获取指定网卡 %s ip 地址失败,使用默认网卡: %v", flags.Interface, err)
|
||||
} else if eth == nil {
|
||||
log.Warnf("指定网卡 %s 无可用 ip 地址,使用默认网卡", flags.Interface)
|
||||
} else {
|
||||
log.Debugf("使用指定网卡 %s ip: %s", eth.Name, eth.Addr.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HttpPack = genHttpPack(eth)
|
||||
} else {
|
||||
httpTools = make(map[string]*Http)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user