MCPcopy
hub / github.com/IceWhaleTech/CasaOS / GetDeviceAllIPv4

Function GetDeviceAllIPv4

pkg/utils/ip_helper/ip.go:60–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58 return address
59}
60func GetDeviceAllIPv4() map[string]string {
61 address := make(map[string]string)
62 addrs, err := net.Interfaces()
63 if err != nil {
64 return address
65 }
66 for _, a := range addrs {
67 if a.Flags&net.FlagLoopback != 0 || a.Flags&net.FlagUp == 0 {
68 continue
69 }
70 addrs, err := a.Addrs()
71 if err != nil {
72 fmt.Println("Error:", err)
73 continue
74 }
75
76 for _, addr := range addrs {
77 if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil {
78 address[a.Name] = ipnet.IP.String()
79 }
80 }
81 }
82 return address
83}
84func HasLocalIP(ip net.IP) bool {
85 if ip.IsLoopback() {
86 return true

Callers 1

GetDeviceInfoMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected