MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / GetIPAddress

Method GetIPAddress

agent-source-code/internal/system/system.go:287–315  ·  view source on GitHub ↗

GetIPAddress gets the primary IP address using network interfaces

()

Source from the content-addressed store, hash-verified

285
286// GetIPAddress gets the primary IP address using network interfaces
287func (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
318func (d *Detector) GetKernelVersion() string {

Callers 1

sendReportFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected