utils/port.go
func FindPortInRange(s string) (int, error) {
	// Take care of csv and single value
	if !strings.Contains(s, "-") {
		ports := strings.Split(strings.TrimSpace(s), ",")
		for _, p := range ports {
			i, err := strconv.Atoi(p)
			if err != nil {
				return 0, err
			}
			err = checkPort(i)
			if err != nil {
				continue
			}
			return i, nil
		}
		return 0, errors.New("all passed ports are unusable")
	}
	// Now take care of ranges
	ports := strings.Split(strings.TrimSpace(s), "-")
	if len(ports) != 2 {
		return 0, errors.New("invalid range passed")
	}
	lower, err := strconv.Atoi(ports[0])
	if err != nil {
		return 0, err
	}
	upper, err := strconv.Atoi(ports[1])
	if err != nil {
		return 0, err
	}
	if upper < lower {
		return 0, errors.New("invalid range passed")
	}
	for i := lower; i <= upper; i++ {
		err = checkPort(i)
		if err != nil {
			continue
		}
		return i, nil
	}
	return 0, errors.New("all passed ports are unusable")
}
func FindPortInRange(s string) (int, error) {
	// Take care of csv and single value
	if !strings.Contains(s, "-") {
		ports := strings.Split(strings.TrimSpace(s), ",")
		for _, p := range ports {
			i, err := strconv.Atoi(p)
			if err != nil {
				return 0, err
			}
			err = checkPort(i)
			if err != nil {
				continue
			}
			return i, nil
		}
		return 0, errors.New("all passed ports are unusable")
	}
	// Now take care of ranges
	ports := strings.Split(strings.TrimSpace(s), "-")
	if len(ports) != 2 {
		return 0, errors.New("invalid range passed")
	}
	lower, err := strconv.Atoi(ports[0])
	if err != nil {
		return 0, err
	}
	upper, err := strconv.Atoi(ports[1])
	if err != nil {
		return 0, err
	}
	if upper < lower {
		return 0, errors.New("invalid range passed")
	}
	for i := lower; i <= upper; i++ {
		err = checkPort(i)
		if err != nil {
			continue
		}
		return i, nil
	}
	return 0, errors.New("all passed ports are unusable")
}
// FindPortInRange Iterate through CSV or Range of ports to find open port
// Valid inputs are "8081", "8081,8085", "8081-8085". Do not combine
// list and range