fix: 网卡绑定问题
This commit is contained in:
@@ -2,11 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
|
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/controllers"
|
"github.com/Mmx233/BitSrunLoginGo/internal/controllers"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/tools"
|
"github.com/Mmx233/BitSrunLoginGo/tools"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -17,23 +15,7 @@ func main() {
|
|||||||
//登录流程
|
//登录流程
|
||||||
var err error
|
var err error
|
||||||
if config.Settings.Basic.Interfaces == "" { //单网卡
|
if config.Settings.Basic.Interfaces == "" { //单网卡
|
||||||
var eth *tools.Eth
|
if err = controllers.Login(nil, false); err != nil {
|
||||||
if flags.Interface != "" {
|
|
||||||
netEth, err := net.InterfaceByName(flags.Interface)
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("获取指定网卡 %s 失败,使用默认网卡: %v", flags.Interface, err)
|
|
||||||
} else {
|
|
||||||
eth, err = tools.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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err = controllers.Login(eth, false); err != nil {
|
|
||||||
log.Errorln("登录出错: ", err)
|
log.Errorln("登录出错: ", err)
|
||||||
if !config.Settings.Log.DebugLevel {
|
if !config.Settings.Log.DebugLevel {
|
||||||
log.Infoln("开启调试日志(debug_level)获取详细信息")
|
log.Infoln("开启调试日志(debug_level)获取详细信息")
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ func Guardian() {
|
|||||||
var c = make(chan bool)
|
var c = make(chan bool)
|
||||||
for {
|
for {
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
|
||||||
_ = recover()
|
|
||||||
}()
|
|
||||||
if config.Settings.Basic.Interfaces == "" { //单网卡
|
if config.Settings.Basic.Interfaces == "" { //单网卡
|
||||||
err := Login(nil, true)
|
err := Login(nil, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package tools
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||||
|
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +18,24 @@ var httpTools map[string]*Http
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if config.Settings.Basic.Interfaces == "" {
|
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 {
|
} else {
|
||||||
httpTools = make(map[string]*Http)
|
httpTools = make(map[string]*Http)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user