-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
52 lines (46 loc) · 969 Bytes
/
main.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
package main
import (
"bufio"
"crypto/tls"
"fmt"
"net/http"
"os"
"sync"
"time"
)
func main() {
var wait sync.WaitGroup
var urls []string
stat, err := os.Stdin.Stat()
if err != nil {
fmt.Fprintf(os.Stderr, "[!] Usage: cat urls.txt | online", err)
os.Exit(3)
}
if (stat.Mode() & os.ModeCharDevice) == 0 {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
urls = append(urls, scanner.Text())
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "[!] Usage: cat urls.txt | online", err)
os.Exit(3)
}
}
wait.Add(len(urls))
for _, url := range urls {
go getHost(url, &wait)
}
wait.Wait()
}
func getHost(url string, wait *sync.WaitGroup) {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
timeout := time.Duration(5 * time.Second)
client := http.Client{
Timeout: timeout,
}
_, err := client.Get(url)
if err == nil {
fmt.Println(url)
}
wait.Done()
}