refactor: 移除二维码和交叉编译,改为列出所有 LAN IP 地址;清理依赖
This commit is contained in:
@@ -5,17 +5,21 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
// GetLANIP returns the first non-loopback IPv4 address.
|
||||
func GetLANIP() (string, error) {
|
||||
// GetLANIPs returns all non-loopback IPv4 addresses.
|
||||
func GetLANIPs() ([]string, error) {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
var ips []string
|
||||
for _, addr := range addrs {
|
||||
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() && ipNet.IP.To4() != nil {
|
||||
return ipNet.IP.String(), nil
|
||||
ips = append(ips, ipNet.IP.String())
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no LAN IP found")
|
||||
if len(ips) == 0 {
|
||||
return nil, fmt.Errorf("no LAN IP found")
|
||||
}
|
||||
return ips, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user