<commit_before>package util

import (
	"net"

	log "github.com/Sirupsen/logrus"
)

//Nw is a static class that provides Network related functions
type Nw struct{}

//NewNw generates a Network object
func NewNw() *Nw {
	myNet := &Nw{}
	return myNet
}

//ParseIP creates an IP object from a string<commit_msg>Feature to autodiscover IP for the host<commit_after>package util

import (
	"net"
	"strings"

	log "github.com/Sirupsen/logrus"
)

//Nw is a static class that provides Network related functions
type Nw struct{}

//NewNw generates a Network object
func NewNw() *Nw {
	myNet := &Nw{}
	return myNet
}

//AutoDiscoverIP attempt to discover the IP for this host
func AutoDiscoverIP() (string, error) {
	ifaces, err := net.Interfaces()
	if err != nil {
		log.Warnln("Failed to get Interfaces", err)
		return "", err
	}

	var ip string
	for _, i := range ifaces {
		if strings.Contains(i.Name, "lo") || strings.Contains(i.Name, "docker") {
			log.Debugln("Skipping interface:", i.Name)
			continue
		}
		addrs, err := i.Addrs()
		if err != nil {
			log.Infoln("Failed to get IPs on Interface", err)
			continue
		}
		// handle err
		for _, addr := range addrs {
			switch v := addr.(type) {
			case *net.IPNet:
				ip = v.IP.String()
				log.Debugln("IPNet:", ip)
			case *net.IPAddr:
				ip = v.IP.String()
				log.Debugln("IPAddr:", ip)
			}
			if len(ip) > 0 {
				break
			}
		}

		log.Infoln("IP Discovered:", ip)
		break
	}

	return ip, nil
}

//ParseIP creates an IP object from a string
{'fraction_non_alphanumeric': 0.12976588628762542, 'fraction_numerical': 0.0006688963210702341, 'mean_word_length': 3.167130919220056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6655703', 'n_tokens_mistral': 591, 'n_tokens_neox': 537, 'n_words': 172}