GetIPAddress gets the primary IP address using network interfaces
()
| 285 | |
| 286 | // GetIPAddress gets the primary IP address using network interfaces |
| 287 | func (d *Detector) GetIPAddress() string { |
| 288 | interfaces, err := net.Interfaces() |
| 289 | if err != nil { |
| 290 | d.logger.WithError(err).Warn("Failed to get network interfaces") |
| 291 | return "" |
| 292 | } |
| 293 | |
| 294 | for _, iface := range interfaces { |
| 295 | // Skip loopback and down interfaces |
| 296 | if iface.Flags&net.FlagLoopback != 0 || iface.Flags&net.FlagUp == 0 { |
| 297 | continue |
| 298 | } |
| 299 | |
| 300 | addrs, err := iface.Addrs() |
| 301 | if err != nil { |
| 302 | continue |
| 303 | } |
| 304 | |
| 305 | for _, addr := range addrs { |
| 306 | if ipnet, ok := addr.(*net.IPNet); ok { |
| 307 | if ipnet.IP.To4() != nil && !ipnet.IP.IsLoopback() { |
| 308 | return ipnet.IP.String() |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return "" |
| 315 | } |
| 316 | |
| 317 | // GetKernelVersion gets the kernel version |
| 318 | func (d *Detector) GetKernelVersion() string { |