我编写了一个代码来区分给出 200 个响应的域和那些没有响应的域。虽然我有 3447 个不同的域,但每次运行程序后我都会得到不同的结果。
我找到域的来源:https ://github.com/opendns/public-domain-lists/blob/master/opendns-random-domains.txt
wc -l example.txt
3447
package main
import (
"bufio"
"log"
"net/http"
"os"
"sync"
"time"
"github.com/panjf2000/ants"
)
var sitelist []string
func check(pool interface{}) {
address := pool.(string)
client := &http.Client{}
client.Timeout = time.Second * 5
req, _ := http.NewRequest("GET", "http://"+address, nil)
if response, err := client.Do(req); err == nil {
status := response.StatusCode
if status == 200 {
// log.Println("Works:", address)
sitelist = append(sitelist, "works:"+address)
return
}
// log.Println("Not working:", address)
sitelist = append(sitelist, "not-works:"+address)
} else {
// log.Println("Not working:", address)
sitelist = append(sitelist, "not-works:"+address)
}
}
func main() {
defer ants.Release()
var wg sync.WaitGroup
p, _ := ants.NewPoolWithFunc(1000, func(i interface{}) {
check(i)
wg.Done()
})
defer p.Release()
file, err := os.Open("example.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
wg.Add(1)
a := scanner.Text()
_ = p.Invoke(string(a))
}
wg.Wait()
log.Println(len(sitelist))
}
go run ./main.go
3385
go run ./main.go
3338
go run ./main.go
3300
这是example.txt
我不明白我做错了什么。谢谢你
富国沪深
相关分类