IP地址
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -42,21 +41,21 @@ var (
|
|||||||
|
|
||||||
// IPAddr IP地址
|
// IPAddr IP地址
|
||||||
func IPAddr(w http.ResponseWriter, r *http.Request) {
|
func IPAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
ipAddrs := make(map[string]string)
|
ipAddrs := []map[string]string{}
|
||||||
interfaces, err := net.Interfaces()
|
interfaces, err := net.Interfaces()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, iface := range interfaces {
|
for _, iface := range interfaces {
|
||||||
var addrs []string
|
addrs := map[string]string{}
|
||||||
for _, v := range iface.Addrs {
|
for _, v := range iface.Addrs {
|
||||||
prefix := strings.Split(v.Addr, "/")[0]
|
prefix := strings.Split(v.Addr, "/")[0]
|
||||||
if strings.Contains(prefix, "::") {
|
if strings.Contains(prefix, "::") {
|
||||||
addrs = append(addrs, fmt.Sprintf("IPv6 %s", prefix))
|
addrs["IPv6"] = prefix
|
||||||
}
|
}
|
||||||
if strings.Contains(prefix, ".") {
|
if strings.Contains(prefix, ".") {
|
||||||
addrs = append(addrs, fmt.Sprintf("IPv4 %s", prefix))
|
addrs["IPv4"] = prefix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ipAddrs[iface.Name] = strings.Join(addrs, " / ")
|
ipAddrs = append(ipAddrs, addrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
services.ResponseWithJson(w, 200, ipAddrs)
|
services.ResponseWithJson(w, 200, ipAddrs)
|
||||||
|
|||||||
Reference in New Issue
Block a user