-
Notifications
You must be signed in to change notification settings - Fork 52
/
bufio_scanner.go
54 lines (50 loc) · 915 Bytes
/
bufio_scanner.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
/*
(c) Yariya
*/
package main
import (
"bufio"
"bytes"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
)
func Scanner() {
if *fetch != "" {
log.Printf("Detected URL Mode.\n")
res, err := http.Get(*fetch)
if err != nil {
log.Fatalln("fetch error")
}
body, err := io.ReadAll(res.Body)
if err != nil {
log.Fatalln("fetch body error")
}
res.Body.Close()
scanner := bufio.NewScanner(bytes.NewReader(body))
for scanner.Scan() {
ip := scanner.Text()
queueChan <- ip
}
} else if *input != "" {
fmt.Printf("Detected FILE Mode.\n")
b, err := os.ReadFile(*input)
if err != nil {
log.Fatalln("open file err")
}
lines := strings.Split(string(b), "\n")
for _, line := range lines {
queueChan <- line
}
} else {
fmt.Printf("Detected ZMAP Mode.\n")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
ip := scanner.Text()
queueChan <- ip
}
}
}