我正在制作一个 _golang git bruteforcer。这有点奇怪,我想这与并发有关。 sync.WaitGroup
这是代码:https ://dpaste.org/vO7y
package main
import { <snipped for brevity> }
// ReadFile : Reads File and returns it's contents
func ReadFile(fileName string) []string { <snipped for brevity> }
func joinString(strs ...string) string { <snipped for brevity> }
// MakeRequest : Makes requests concurrently
func MakeRequest(client *http.Client, url string, useragent string, ch chan<- string, wg *sync.WaitGroup) {
defer wg.Done()
// start := time.Now()
request, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Println(err)
return
}
request.Header.Set("User-Agent", useragent)
response, err := client.Do(request)
if err != nil {
return
}
// secs := time.Since(start).Seconds()
if response.StatusCode < 400 {
// fmt.Printf("Time elapsed %f", secs)
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
bodyString := string(bodyBytes)
notGit, err := regexp.MatchString("<html>", strings.ToLower(bodyString))
if !notGit && len(bodyString) > 0 { // empty pages and html pages shouldn't be included
fmt.Println(bodyString)
ch <- fmt.Sprintf(" %s ", Green(url))
}
}
}
在职的 :
它从文件中读取 url 并/.git, /.git/HEAD, /.git/description, /.git/index在网络服务器上进行检查。
问题: 如果我将http.Client超时更改为2 seconds它将在 2 秒内完成,如果是 50 秒,它将等到 50 秒,输入文件包含 10 个 url 或 500 个 url 都没有关系。我的理解是,如果有更多数量的 url,它将等到 goroutine 传递的最后一个 URL 超时。
正如阿德里安在评论中提到的那样,它看起来不像是一个并发问题,这就是其中一个主要问题是我无法确定这里的确切问题是什么
心有法竹
青春有我
随时随地看视频慕课网APP
相关分类