-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubstatus.go
94 lines (79 loc) · 1.94 KB
/
substatus.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"bufio"
"net/url"
"strings"
"path"
"net"
"net/http"
"os"
"time"
"sync"
"crypto/tls"
)
func printResponseCode(client *http.Client, url string) {
req, err := http.NewRequest("GET", url, nil)
if err!= nil {
fmt.Println("Couldn't get " + url)
os.Exit(1)
}
req.Header.Add("Connection", "close")
req.Close = true
resp, err := client.Do(req)
if err != nil {
fmt.Println("Couldn't get" + url)
return
}
fmt.Printf("%s [%d]\n", url, resp.StatusCode)
}
func main() {
timeout := time.Duration(10000000000)
var tr = &http.Transport{
MaxIdleConns: 30,
IdleConnTimeout: time.Second,
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: timeout,
KeepAlive: time.Second,
}).DialContext,
}
re := func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
client := &http.Client{
Transport: tr,
CheckRedirect: re,
Timeout: timeout,
}
allURLs := make(chan string)
var httpWG sync.WaitGroup
for i := 0; i < 20; i++ {
httpWG.Add(1)
go func() {
for url := range allURLs {
printResponseCode(client, url)
continue
}
httpWG.Done()
}()
}
// read from stdin
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
domain := strings.ToLower(sc.Text())
u, err := url.Parse(domain)
if err != nil {
fmt.Println("Couldn't parse")
os.Exit(1)
}
split := strings.Split(u.Hostname(), ".")
u.Path = path.Join(u.Path, split[0])
allURLs <- domain
allURLs <- u.String()
allURLs <- u.String()+"/"
}
close(allURLs)
httpWG.Wait()
}