fix
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"admin/admin"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -158,28 +157,3 @@ func listenPort(listenOn string) (uint64, error) {
|
||||
}
|
||||
return strconv.ParseUint(portStr, 10, 64)
|
||||
}
|
||||
|
||||
// getContainerIntranetIP 获取容器内网IPv4(排除回环地址)
|
||||
func getContainerIntranetIP() (string, error) {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
ipNet, ok := addr.(*net.IPNet)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
// 跳过127.0.0.1回环地址
|
||||
if ipNet.IP.IsLoopback() {
|
||||
continue
|
||||
}
|
||||
// 只取IPv4地址
|
||||
ipv4 := ipNet.IP.To4()
|
||||
if ipv4 != nil {
|
||||
return ipv4.String(), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("未检测到可用内网IPv4地址")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user