dou4624
2018-04-17 09:55
浏览 39
已采纳

使用无缓冲通道的Golang并发问题

I have recently started golang programming. I created a tool in golang that could bruteforce subdomains using golang concurrency. The problem is that it just shows first few results. I mean if the threads i specify are 10, it shows 10, if 100 then it shows 100. Any solutions for this. I am following this example.

func CheckWildcardSubdomain(state *State, domain string, words <-chan string, wg *sync.WaitGroup) {
    defer wg.Done()

    for {
        preparedSubdomain := <-words + "." + domain
        ipAddress, err := net.LookupHost(preparedSubdomain)

        if err == nil {
            if !state.WildcardIPs.ContainsAny(ipAddress) {
                if state.Verbose == true {
                    fmt.Printf("
%s", preparedSubdomain)
                }

                state.FinalResults = append(state.FinalResults, preparedSubdomain)
            }
        }
    }
}

func RemoveWildcardSubdomains(state *State, subdomains []string) []string {
    var wg sync.WaitGroup
    var channel = make(chan string)

    wg.Add(state.Threads)

    for i := 0; i < state.Threads; i++ {
        go CheckWildcardSubdomain(state, state.Domain, channel, &wg)
    }

    for _, entry := range subdomains {
        sub := strings.Join(strings.Split(entry, ".")[:2][:], ".")
        channel <- sub
    }

    close(channel)
    wg.Wait()

    return state.FinalResults
}

Thanks in advance for your help.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题