forked from shadow1ng/fscan
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog.go
86 lines (78 loc) · 1.83 KB
/
log.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
package common
import (
"fmt"
"os"
"strings"
"sync"
"time"
)
var Num int64
var End int64
var Results = make(chan string)
var Start = true
var LogSucTime int64
var LogErrTime int64
var WaitTime int64
var Silent bool
var LogWG sync.WaitGroup
func init() {
go SaveLog()
}
func LogSuccess(result string) {
LogWG.Add(1)
LogSucTime = time.Now().Unix()
Results <- result
}
func SaveLog() {
for result := range Results {
if Silent == false || strings.Contains(result, "[+]") || strings.Contains(result, "[*]") {
fmt.Println(result)
}
if IsSave {
WriteFile(result, Outputfile)
}
LogWG.Done()
}
}
func WriteFile(result string, filename string) {
var text = []byte(result + "\n")
fl, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0777)
if err != nil {
fmt.Printf("Open %s error, %v\n", filename, err)
return
}
_, err = fl.Write(text)
fl.Close()
if err != nil {
fmt.Printf("Write %s error, %v\n", filename, err)
}
}
func LogError(errinfo interface{}) {
if WaitTime == 0 {
fmt.Println(fmt.Sprintf("已完成 %v/%v %v", End, Num, errinfo))
} else if (time.Now().Unix()-LogSucTime) > WaitTime && (time.Now().Unix()-LogErrTime) > WaitTime {
fmt.Println(fmt.Sprintf("已完成 %v/%v %v", End, Num, errinfo))
LogErrTime = time.Now().Unix()
}
}
func CheckErrs(err error) bool {
if err == nil {
return false
}
errs := []string{
"closed by the remote host", "too many connections",
"i/o timeout", "EOF", "A connection attempt failed",
"established connection failed", "connection attempt failed",
"Unable to read", "is not allowed to connect to this",
"no pg_hba.conf entry",
"No connection could be made",
"invalid packet size",
"bad connection",
}
for _, key := range errs {
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower(key)) {
return true
}
}
return false
}