Skip to content

Commit 8563eb0

Browse files
committed
Update 0.4.4 beta
1 parent 2e87cee commit 8563eb0

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

infoscan/api/api.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import (
44
"GScan/infoscan/config"
55
"GScan/infoscan/dao"
66
"GScan/infoscan/service/Crawler"
7-
"GScan/pkg"
8-
"bufio"
97
"context"
108
"fmt"
11-
"log"
12-
"os"
13-
"path/filepath"
149
"time"
1510
)
1611

@@ -25,30 +20,12 @@ func NewApi(db dao.IDAO, config *config.Config) *Api {
2520
config: config,
2621
}
2722
}
28-
func (a *Api) StartCrawlerJob() (name string, id uint) {
23+
func (a *Api) StartCrawlerJob(urls []string) (name string, id uint) {
2924
//pproff CPU占用监控
3025
//pproff, _ := os.OpenFile(filepath.Join(Config.ResultPath, fmt.Sprintf("%s.cpu.pprof", time.Now().Format("2006-01-02 15-04-05"))), os.O_CREATE|os.O_RDWR, 0644)
3126
//defer pproff.Close()
3227
//pprof.StartCPUProfile(pproff)
3328
//defer pprof.StopCPUProfile()
34-
// url 列表读取
35-
f, err := os.Open("url.txt")
36-
if err != nil {
37-
log.Fatal(err)
38-
}
39-
defer f.Close()
40-
var urls []string
41-
scanner := bufio.NewScanner(f)
42-
for scanner.Scan() {
43-
urls = append(urls, scanner.Text())
44-
}
45-
if err := scanner.Err(); err != nil {
46-
log.Fatal(err)
47-
}
48-
fmt.Printf("扫描%d个URL.(Y/N):", len(urls))
49-
if !pkg.AskForConfirmation() {
50-
return "", 0
51-
}
5229
//启动任务
5330
crawlerJob := Crawler.NewCrawlerJob(a.config, a.db, fmt.Sprintf("%s扫描%d个URL", time.Now().Format("2006-01-02 15-04-05"), len(urls)), urls)
5431
ctx, _ := context.WithCancel(context.Background())
@@ -57,7 +34,8 @@ func (a *Api) StartCrawlerJob() (name string, id uint) {
5734
}
5835

5936
func (a *Api) Out2Excel(jobID uint, filename string) {
60-
Crawler.Out2Excel(jobID, a.db, filepath.Join(a.config.ResultPath, filename))
37+
//Crawler.Out2Excel(jobID, a.db, filepath.Join(a.config.ResultPath, filename))
38+
Crawler.Out2Excel(jobID, a.db, filename)
6139
}
6240

6341
func (a *Api) GetJobs() {

infoscan/cmd/main.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"GScan/infoscan/dao/sqlite"
77
"GScan/pkg"
88
"GScan/pkg/logger"
9+
"bufio"
10+
"flag"
911
"fmt"
1012
"log"
1113
"os"
@@ -15,18 +17,33 @@ import (
1517
)
1618

1719
var a *api.Api
20+
var Config *config.Config
21+
var urlf = flag.String("u", "url.txt", "url text path")
22+
var outfile = flag.String("o", "outfile.xlsx", "outfile excel path")
1823

1924
func main() {
2025
if len(os.Args) >= 2 {
2126
switch os.Args[1] {
27+
case "run":
28+
//infoscan run -u url.txt -o name.xlsx
29+
if err := flag.CommandLine.Parse(os.Args[2:]); err != nil {
30+
log.Fatal(err)
31+
}
32+
urls, err := geturl(*urlf)
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
_, jobID := a.StartCrawlerJob(urls)
37+
a.Out2Excel(jobID, *outfile)
38+
fmt.Print("Complete!")
2239
case "ls":
2340
a.GetJobs()
2441
case "export":
2542
atoi, err := strconv.Atoi(os.Args[2])
2643
if err != nil {
2744
log.Fatal(err)
2845
}
29-
a.Out2Excel(uint(atoi), fmt.Sprintf("%s-ExportJobID-%d.xlsx", time.Now().Format("2006-01-02 15-04-05"), atoi))
46+
a.Out2Excel(uint(atoi), filepath.Join(Config.ResultPath, fmt.Sprintf("%s-ExportJobID-%d.xlsx", time.Now().Format("2006-01-02 15-04-05"), atoi)))
3047
default:
3148
fmt.Print(`InfoScan
3249
@@ -36,12 +53,20 @@ Usage:
3653
infoscan.exe export <JobID> #导出任务结果`)
3754
}
3855
} else {
39-
jobname, jobID := a.StartCrawlerJob()
56+
urls, err := geturl("url.txt")
57+
if err != nil {
58+
log.Fatal(err)
59+
}
60+
fmt.Printf("扫描%d个URL.(Y/N):", len(urls))
61+
if !pkg.AskForConfirmation() {
62+
return
63+
}
64+
jobname, jobID := a.StartCrawlerJob(urls)
4065
if jobID != 0 {
4166
fmt.Printf("JobID:%d Name:%s 运行完成\n", jobID, jobname)
4267
fmt.Printf("是否导出(Y/N):")
4368
if pkg.AskForConfirmation() {
44-
a.Out2Excel(jobID, jobname+".xlsx")
69+
a.Out2Excel(jobID, filepath.Join(Config.ResultPath, jobname+".xlsx"))
4570
}
4671
}
4772
}
@@ -54,7 +79,7 @@ func banner() {
5479
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
5580
██ ██ ████ ██ ██████ ███████ ██████ ██ ██ ██ ████
5681
---------------------------------------------------------------
57-
Version: 0.4.2beta
82+
Version: 0.4.4beta
5883
Email: i@vshex.com
5984
Github: https://github.com/Ymjie/GScan
6085
---------------------------------------------------------------`)
@@ -67,7 +92,7 @@ func init() {
6792
if err != nil {
6893
log.Fatal(err)
6994
}
70-
Config := c
95+
Config = c
7196
os.Mkdir(Config.ResultPath, 0644)
7297
os.Mkdir(Config.LogPath, 0644)
7398
//设置日志
@@ -80,3 +105,20 @@ func init() {
80105
//api 初始化
81106
a = api.NewApi(DB, Config)
82107
}
108+
func geturl(urlpath string) ([]string, error) {
109+
// url 列表读取
110+
f, err := os.Open(urlpath)
111+
if err != nil {
112+
return nil, err
113+
}
114+
defer f.Close()
115+
var urls []string
116+
scanner := bufio.NewScanner(f)
117+
for scanner.Scan() {
118+
urls = append(urls, scanner.Text())
119+
}
120+
if err := scanner.Err(); err != nil {
121+
return nil, err
122+
}
123+
return urls, nil
124+
}

infoscan/cmd/whitelist.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ baike.com
4343
dzwww.com
4444
e23.cn
4545
dzng.com
46-
ihwrm.com
46+
ihwrm.com
47+
ql1d.com

0 commit comments

Comments
 (0)