mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Backend update.
This commit is contained in:
parent
f49630558d
commit
90bf6be882
9 changed files with 66 additions and 28 deletions
|
|
@ -18,12 +18,25 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
|||
ifs, err := net.Interfaces()
|
||||
if err != nil {
|
||||
MCRMLog(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, ifi := range ifs {
|
||||
// Skip interfaces that are down
|
||||
if ifi.Flags&net.FlagUp == 0 {
|
||||
continue
|
||||
}
|
||||
// Skip loopback interfaces
|
||||
if ifi.Flags&net.FlagLoopback != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
addrs, err := ifi.Addrs()
|
||||
if err != nil {
|
||||
MCRMLog(err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
|
||||
|
|
@ -34,10 +47,18 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
|||
ip = v.IP
|
||||
}
|
||||
|
||||
if ip != nil && ip.To4() != nil {
|
||||
json.NewEncoder(w).Encode(ip.String())
|
||||
return
|
||||
if ip == nil || ip.To4() == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip APIPA (169.254.x.x) addresses
|
||||
if ip.IsLinkLocalUnicast() {
|
||||
continue
|
||||
}
|
||||
|
||||
// Found a good IP, return it
|
||||
json.NewEncoder(w).Encode(ip.String())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue