Skip to content

Commit 41a05fc

Browse files
committed
error handle and optimize
1 parent c792ed3 commit 41a05fc

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

main/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func init() {
1818
config.SpecificInit(configFile)
1919
if config.C.ServerUrl == "http://" || config.C.ServerUrl == "" || config.C.PortList == "" {
2020
Error.HandleFatal(errors.New("请配置config.json"))
21+
return
2122
}
2223
}
2324

pkg/data.go

-33
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package pkg
22

33
import (
44
"bufio"
5-
"fmt"
65
"github.com/shadowabi/Serverless_PortScan_rebuild/config"
76
"github.com/shadowabi/Serverless_PortScan_rebuild/utils/Error"
87
"os"
98
"regexp"
10-
"sort"
119
"strings"
1210
)
1311

@@ -62,34 +60,3 @@ func RemoveDuplicates(reqList []string) []string {
6260
}
6361
return result
6462
}
65-
66-
func GetResult(respData ...ResponseData) (writeResultList []string) {
67-
if len(respData) != 0 {
68-
for _, data := range respData {
69-
dataBody := strings.Trim(data.body, "\"")
70-
ports := strings.Split(dataBody, ",")
71-
for _, port := range ports {
72-
fmt.Println(fmt.Sprintf("[+] %s:%s TCP OPEN.", data.host, port))
73-
writeResult := strings.Join([]string{data.host, ":", port}, "")
74-
writeResultList = append(writeResultList, writeResult)
75-
}
76-
}
77-
}
78-
return writeResultList
79-
}
80-
81-
func WriteToFile(writeResultList []string, output string) {
82-
file, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
83-
Error.HandlePanic(err)
84-
defer file.Close()
85-
86-
writer := bufio.NewWriter(file)
87-
defer writer.Flush()
88-
89-
sort.Strings(writeResultList)
90-
if len(writeResultList) != 0 {
91-
for _, i := range writeResultList {
92-
fmt.Fprintln(writer, i)
93-
}
94-
}
95-
}

pkg/output.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package pkg
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"github.com/shadowabi/Serverless_PortScan_rebuild/utils/Error"
7+
"os"
8+
"sort"
9+
"strings"
10+
)
11+
12+
func GetResult(respData ...ResponseData) (writeResultList []string) {
13+
if len(respData) != 0 {
14+
for _, data := range respData {
15+
dataBody := strings.Trim(data.body, "\"")
16+
ports := strings.Split(dataBody, ",")
17+
for _, port := range ports {
18+
fmt.Println(fmt.Sprintf("[+] %s:%s TCP OPEN.", data.host, port))
19+
writeResult := strings.Join([]string{data.host, ":", port}, "")
20+
writeResultList = append(writeResultList, writeResult)
21+
}
22+
}
23+
}
24+
return writeResultList
25+
}
26+
27+
func WriteToFile(writeResultList []string, output string) {
28+
file, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
29+
Error.HandlePanic(err)
30+
defer file.Close()
31+
32+
writer := bufio.NewWriter(file)
33+
defer writer.Flush()
34+
35+
sort.Strings(writeResultList)
36+
if len(writeResultList) != 0 {
37+
for _, i := range writeResultList {
38+
fmt.Fprintln(writer, i)
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)