-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckurl.go
More file actions
62 lines (54 loc) · 1.45 KB
/
Copy pathcheckurl.go
File metadata and controls
62 lines (54 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bufio"
"flag"
"fmt"
"sync"
"os"
"net/http"
"net"
"time"
"crypto/tls"
)
func main() {
concurrencyPtr := flag.Int("t", 8, "Number of threads to utilise. Default is 8.")
flag.Parse()
client := &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Dial: (&net.Dialer{Timeout: 0, KeepAlive: 0}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
}}
numWorkers := *concurrencyPtr
work := make(chan string)
go func() {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
work <- s.Text()
}
close(work)
}()
wg := &sync.WaitGroup{}
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go doWork(work, client, wg)
}
wg.Wait()
}
func doWork(work chan string, client *http.Client, wg *sync.WaitGroup) {
defer wg.Done()
for url := range work {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Println(999, err)
continue
}
req.Header.Set("Connection", "close")
resp, err := client.Do(req)
if err != nil {
fmt.Println(999, err, url)
continue
}
resp.Body.Close()
fmt.Println(resp.StatusCode, url)
}
}