drivers/virtualbox/network.go
func listHostInterfaces(hif HostInterfaces, excludeNets map[string]*hostOnlyNetwork) (map[string]*net.IPNet, error) {
	ifaces, err := hif.Interfaces()
	if err != nil {
		return nil, err
	}
	m := map[string]*net.IPNet{}

	for _, iface := range ifaces {
		addrs, err := hif.Addrs(&iface)
		if err != nil {
			return nil, err
		}

		// Check if an address of the interface is in the list of excluded addresses
		ifaceExcluded := false
		for _, a := range addrs {
			switch ipnet := a.(type) {
			case *net.IPNet:
				_, excluded := excludeNets[ipnet.String()]
				if excluded {
					ifaceExcluded = true
					break
				}
			}
		}

		// If excluded, or not up, or a loopback interface, skip the interface
		if ifaceExcluded || iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
			continue
		}

		// This is a host interface, so add all its addresses to the map
		for _, a := range addrs {
			switch ipnet := a.(type) {
			case *net.IPNet:
				m[ipnet.String()] = ipnet
			}
		}
	}
	return m, nil
}
func listHostInterfaces(hif HostInterfaces, excludeNets map[string]*hostOnlyNetwork) (map[string]*net.IPNet, error) {
	ifaces, err := hif.Interfaces()
	if err != nil {
		return nil, err
	}
	m := map[string]*net.IPNet{}

	for _, iface := range ifaces {
		addrs, err := hif.Addrs(&iface)
		if err != nil {
			return nil, err
		}

		// Check if an address of the interface is in the list of excluded addresses
		ifaceExcluded := false
		for _, a := range addrs {
			switch ipnet := a.(type) {
			case *net.IPNet:
				_, excluded := excludeNets[ipnet.String()]
				if excluded {
					ifaceExcluded = true
					break
				}
			}
		}

		// If excluded, or not up, or a loopback interface, skip the interface
		if ifaceExcluded || iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
			continue
		}

		// This is a host interface, so add all its addresses to the map
		for _, a := range addrs {
			switch ipnet := a.(type) {
			case *net.IPNet:
				m[ipnet.String()] = ipnet
			}
		}
	}
	return m, nil
}
// listHostInterfaces returns a map of net.IPNet addresses of host interfaces that are "UP" and not loopback adapters
// and not virtualbox host-only networks (given by excludeNets), keyed by CIDR string.