pingscanner.go
func (d PingScanner) Scan() (aliveIPs []string, err error) {
	var hostsInCidr []string
	if hostsInCidr, err = expandCidrIntoIPs(d.CIDR); err != nil {
		return nil, err
	}
	pingChan := make(chan string, d.NumOfConcurrency)
	pongChan := make(chan pong, len(hostsInCidr))
	doneChan := make(chan []pong)

	for i := 0; i < d.NumOfConcurrency; i++ {
		go ping(pingChan, pongChan, d.PingOptions...)
	}

	go receivePong(len(hostsInCidr), pongChan, doneChan)

	for _, ip := range hostsInCidr {
		pingChan <- ip
	}

	alives := <-doneChan
	for _, a := range alives {
		aliveIPs = append(aliveIPs, a.IP)
	}
	sort.Strings(aliveIPs)
	return
}
func (d PingScanner) Scan() (aliveIPs []string, err error) {
	var hostsInCidr []string
	if hostsInCidr, err = expandCidrIntoIPs(d.CIDR); err != nil {
		return nil, err
	}
	pingChan := make(chan string, d.NumOfConcurrency)
	pongChan := make(chan pong, len(hostsInCidr))
	doneChan := make(chan []pong)

	for i := 0; i < d.NumOfConcurrency; i++ {
		go ping(pingChan, pongChan, d.PingOptions...)
	}

	go receivePong(len(hostsInCidr), pongChan, doneChan)

	for _, ip := range hostsInCidr {
		pingChan <- ip
	}

	alives := <-doneChan
	for _, a := range alives {
		aliveIPs = append(aliveIPs, a.IP)
	}
	sort.Strings(aliveIPs)
	return
}
// Scan ping to hosts in CIDR range.