Skip to content

Commit a34db2e

Browse files
committed
增加信息,开源吧~
1 parent f3417b8 commit a34db2e

File tree

29 files changed

+5129
-316
lines changed

29 files changed

+5129
-316
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
# Output of the go coverage tool, specifically when used with LiteIDE
1313
*.out
14-
14+
config.yaml
1515
/res
1616
/out
17+
/Report
1718

1819
# Dependency directories (remove the comment below to include it)
1920
# vendor/

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

22
# ENScan_GO
33

4-
ENScanGo 是现有开源项目 [ENScan](https://github.com/wgpsec/ENScan) 的升级版本,为避免滥用导致API失效,目前**仅开源部分代码!**
4+
ENScanGo 是现有开源项目 [ENScan](https://github.com/wgpsec/ENScan) 的GO升级版本
5+
6+
**仅用于学习参考,请勿遵守相关法律规定**
57

68
![](https://shields.io/badge/Go-1.17-green?logo=go)
79

@@ -34,10 +36,9 @@ ENScanGo 是现有开源项目 [ENScan](https://github.com/wgpsec/ENScan) 的升
3436
- 使用支持以下API,并支持合并数据导出
3537
- 爱企查
3638
- 天眼查
37-
- 企查查(暂未开放)
3839
- 阿拉丁
3940
- 酷安
40-
- 小蓝本(暂未开放)
41+
- 七麦数据
4142

4243
- 查询信息
4344
- ICP备案
@@ -61,7 +62,7 @@ ENScanGo 是现有开源项目 [ENScan](https://github.com/wgpsec/ENScan) 的升
6162
-f string 包含公司关键词的文件一行一个
6263
-field string 获取字段信息 eg website
6364
-i string 公司ID(根据你查询的type不同ID不同)
64-
-invest-num int 投资比例 eg 100
65+
-invest int 投资比例 eg 100
6566
-invest-rd 投资比例不明确(可能不是完全控股)
6667
-is-branch 查询分支机构(分公司)详细信息ICP备案APP等
6768
-is-debug 是否显示debug详细信息
@@ -138,15 +139,15 @@ Eg:快速收集小米相关信息 默认收集:企业基本信息、微博
138139
#### 只想获取备案信息
139140

140141
```shell
141-
./ENScanPublic_amd64_linux -n 小米 -field website
142+
./ENScanPublic_amd64_linux -n 小米 -field icp
142143
```
143144

144145
[![asciicast](https://asciinema.org/a/460252.svg)](https://asciinema.org/a/460252)
145146

146147
#### 获取占股100的子公司下所有ICP备案网站
147148

148149
```
149-
./ENScanPublic_amd64_linux -n 小米通讯 -invest-num 100 -field website
150+
./ENScanPublic_amd64_linux -n 小米通讯 -invest-num 100 -field icp
150151
```
151152

152153
![image-20220106224603776](README/image-20220106224603776.png)

api/web.go

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
package api
2+
3+
import (
4+
"fmt"
5+
"github.com/gin-gonic/gin"
6+
"github.com/wgpsec/ENScan/common"
7+
"github.com/wgpsec/ENScan/common/outputfile"
8+
"github.com/wgpsec/ENScan/common/utils"
9+
"github.com/wgpsec/ENScan/common/utils/gologger"
10+
"github.com/wgpsec/ENScan/db"
11+
"github.com/wgpsec/ENScan/runner"
12+
"go.mongodb.org/mongo-driver/bson"
13+
"golang.org/x/net/context"
14+
"strconv"
15+
"time"
16+
)
17+
18+
func RunApiWeb(options *common.ENOptions) {
19+
gin.SetMode(gin.TestMode)
20+
r := gin.Default()
21+
22+
r.GET("/", func(c *gin.Context) {
23+
c.JSON(200, gin.H{
24+
"code": 200,
25+
"message": "OK",
26+
})
27+
})
28+
29+
r.GET("/status", func(c *gin.Context) {
30+
queues, err := db.RmqC.GetOpenQueues()
31+
stats, err := db.RmqC.CollectStats(queues)
32+
if err != nil {
33+
fmt.Println(err.Error())
34+
}
35+
fmt.Println(stats)
36+
c.JSON(200, gin.H{
37+
"code": 200,
38+
"message": "OK",
39+
"data": stats,
40+
})
41+
})
42+
r.POST("/api/info", func(ginCtx *gin.Context) {
43+
token := ginCtx.PostForm("orgname")
44+
if token == "" {
45+
ginCtx.JSON(400, gin.H{
46+
"code": 400,
47+
"message": "orgname is empty",
48+
})
49+
return
50+
}
51+
if ginCtx.PostForm("update") == "" {
52+
var result common.DBEnInfos
53+
collection := db.MongoBb.Database("ENScan").Collection("enterprise_info")
54+
err := collection.FindOne(context.TODO(), bson.M{"name": token}).Decode(&result)
55+
if err == nil {
56+
if result.InTime.Sub(time.Now()).Hours() < 720 {
57+
ginCtx.JSON(200, gin.H{
58+
"code": 400,
59+
"message": "30DAY",
60+
})
61+
return
62+
}
63+
} else {
64+
gologger.Errorf("NO")
65+
}
66+
}
67+
68+
options.ScanType = ginCtx.PostForm("type")
69+
70+
if ginCtx.PostForm("invest_rd") == "true" {
71+
options.IsInvestRd = true
72+
}
73+
if ginCtx.PostForm("branch") == "true" {
74+
options.IsGetBranch = true
75+
}
76+
//if ginCtx.PostForm("is_branch") == "true" {
77+
// options.IsSearchBranch = true
78+
//}
79+
if ginCtx.PostForm("proxy") != "" {
80+
options.Proxy = ginCtx.PostForm("proxy")
81+
}
82+
field := ginCtx.PostForm("field")
83+
options.GetFlags = field
84+
options.DelayMaxTime = 5
85+
options.InvestNum = utils.FormatInvest(ginCtx.PostForm("invest"))
86+
87+
options.KeyWord = token
88+
err := runner.AddTask(options)
89+
if err != nil {
90+
ginCtx.JSON(200, gin.H{
91+
"code": 500,
92+
"message": err.Error(),
93+
})
94+
return
95+
}
96+
ginCtx.JSON(200, gin.H{
97+
"code": 200,
98+
"message": "OK",
99+
"data": "Add OK",
100+
})
101+
102+
})
103+
r.GET("/api/stockchart", func(ginCtx *gin.Context) {
104+
orgname := ginCtx.Query("orgname")
105+
search := ginCtx.Query("search")
106+
//默认去重
107+
duplicate := ginCtx.Query("duplicate")
108+
IsDuplicate := true
109+
if duplicate == "true" {
110+
IsDuplicate = true
111+
} else if duplicate == "false" {
112+
IsDuplicate = false
113+
}
114+
if orgname == "" && search == "" {
115+
ginCtx.JSON(400, gin.H{
116+
"code": 400,
117+
"message": "orgname or search is empty",
118+
})
119+
return
120+
}
121+
if search != "" {
122+
orgname = runner.SearchByKeyword(search, options.ScanType, options)
123+
}
124+
options.GetFlags = "invest,partner"
125+
options.InvestNum = -1
126+
common.Parse(options)
127+
reEnsList := make(map[string][]map[string]interface{})
128+
reEnsList = runner.GetInfo(runner.InfoDto{OrgName: orgname, SearchList: []string{"enterprise_info", "partner", "invest"}, InvestNum: -1, Depth: 0, IsGetNext: true, IsDuplicate: IsDuplicate, DuMap: make(map[string]map[string]bool)}, reEnsList, 0, options)
129+
if len(reEnsList) > 0 {
130+
ginCtx.JSON(200, gin.H{
131+
"code": 200,
132+
"message": "OK",
133+
"data": reEnsList,
134+
})
135+
} else {
136+
ginCtx.JSON(200, gin.H{
137+
"code": 404,
138+
"message": orgname + " NO DATA",
139+
})
140+
}
141+
})
142+
r.GET("/api/info", func(ginCtx *gin.Context) {
143+
//搜索参数
144+
orgname := ginCtx.Query("orgname")
145+
search := ginCtx.Query("search")
146+
types := ginCtx.Query("type")
147+
//筛选参数,查询参数
148+
field := ginCtx.Query("field")
149+
duplicate := ginCtx.Query("duplicate")
150+
151+
depth, _ := strconv.Atoi(ginCtx.Query("depth"))
152+
InvestNum, _ := strconv.Atoi(ginCtx.Query("invest"))
153+
holds := ginCtx.Query("holds")
154+
supplier := ginCtx.Query("supplier")
155+
156+
if ginCtx.Query("branch") == "true" {
157+
options.IsGetBranch = true
158+
} else {
159+
options.IsGetBranch = false
160+
}
161+
outputs := ginCtx.Query("output")
162+
if orgname == "" && search == "" {
163+
ginCtx.JSON(400, gin.H{
164+
"code": 400,
165+
"message": "orgname or search is empty",
166+
})
167+
return
168+
}
169+
if search != "" {
170+
if types == "" {
171+
types = "aqc"
172+
} else {
173+
if _, ok := common.ScanTypeKeys[types]; !ok {
174+
gologger.Errorf("没有这个%s查询方式\n支持列表\n%s", types, common.ScanTypeKeys)
175+
ginCtx.JSON(500, gin.H{
176+
"code": 500,
177+
"message": fmt.Sprintf("没有%s方式,支持列表:%s", types, common.ScanTypeKeys),
178+
})
179+
return
180+
}
181+
}
182+
orgname = runner.SearchByKeyword(search, types, options)
183+
}
184+
IsDuplicate := true
185+
if duplicate == "true" {
186+
IsDuplicate = true
187+
} else if duplicate == "false" {
188+
IsDuplicate = false
189+
}
190+
if types != "" {
191+
options.ScanType = types
192+
}
193+
options.GetFlags = field
194+
options.ScanType = "all"
195+
options.GetType = []string{}
196+
common.Parse(options)
197+
reEnsList := make(map[string][]map[string]interface{})
198+
searchList := []string{"enterprise_info"}
199+
searchList = append(searchList, options.GetField...)
200+
if holds == "true" {
201+
searchList = append(searchList, "holds")
202+
}
203+
if supplier == "true" {
204+
searchList = append(searchList, "supplier")
205+
}
206+
if InvestNum != 0 {
207+
searchList = append(searchList, "invest")
208+
}
209+
gologger.Debugf("searchList: %s\n", searchList)
210+
if depth == 0 {
211+
depth = 0
212+
}
213+
reEnsList = runner.GetInfo(runner.InfoDto{OrgName: orgname, SearchType: options.GetType, SearchList: searchList, InvestNum: InvestNum, Depth: depth, IsGetNext: false, IsDuplicate: IsDuplicate, DuMap: make(map[string]map[string]bool)}, reEnsList, 0, options)
214+
215+
if len(reEnsList) > 0 {
216+
if outputs == "file" {
217+
ginCtx.Header("Content-Type", "application/octet-stream")
218+
ginCtx.Header("Content-Disposition", "attachment; filename="+orgname+".xlsx")
219+
ginCtx.Header("Content-Transfer-Encoding", "binary")
220+
//fmt.Println(reEnsList)
221+
err := outputfile.OutPutExcelByMergeJson(reEnsList, ginCtx.Writer)
222+
if err != nil {
223+
ginCtx.JSON(500, gin.H{
224+
"code": 500,
225+
"message": "导出失败",
226+
})
227+
return
228+
}
229+
} else {
230+
ginCtx.JSON(200, gin.H{
231+
"code": 200,
232+
"message": "OK",
233+
"data": reEnsList,
234+
"columns": outputfile.ENSMapLN,
235+
})
236+
return
237+
}
238+
239+
} else {
240+
if res, _ := db.RedisBb.Get("ENScanK:" + orgname).Result(); orgname != "" && res != "" {
241+
ginCtx.JSON(200, gin.H{
242+
"code": 000,
243+
"inTime": res,
244+
"message": fmt.Sprintf("关键词 %s 于 %s 入库,正在队列查询,请刷新重试", orgname, res),
245+
})
246+
return
247+
}
248+
249+
ginCtx.JSON(200, gin.H{
250+
"code": 404,
251+
"message": fmt.Sprintf("没有查询到 %s,任务队列已添加", orgname),
252+
})
253+
return
254+
}
255+
256+
})
257+
258+
gologger.Infof("API 模式已开启 :31000\n")
259+
err := r.Run(":31000")
260+
if err != nil {
261+
gologger.Fatalf("web api run error: %v", err)
262+
return
263+
} else {
264+
gologger.Infof("web api run success\n\n")
265+
}
266+
}

build.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
appName="enscan"
4+
builtAt="$(date +'%F %T %z')"
5+
goVersion=$(go version | sed 's/go version //')
6+
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
7+
gitCommit=$(git log --pretty=format:"%h" -1)
8+
9+
if [ "$1" == "release" ]; then
10+
gitTag=$(git describe --abbrev=0 --tags)
11+
else
12+
gitTag=build-next
13+
fi
14+
15+
echo "build version: $gitTag"
16+
17+
ldflags="\
18+
-w -s \
19+
-X 'github.com/wgpsec/ENScan/common.BuiltAt=$builtAt' \
20+
-X 'github.com/wgpsec/ENScan/common.GoVersion=$goVersion' \
21+
-X 'github.com/wgpsec/ENScan/common.GitAuthor=$gitAuthor' \
22+
-X 'github.com/wgpsec/ENScan/common.GitCommit=$gitCommit' \
23+
-X 'github.com/wgpsec/ENScan/common.GitTag=$gitTag' \
24+
"
25+
26+
if [ "$1" == "release" ]; then
27+
xgo -out enscan -ldflags="$ldflags" .
28+
else
29+
xgo -targets=linux/amd64,windows/amd64,darwin/amd64 -out enscan -ldflags="$ldflags" .
30+
fi
31+
32+
mkdir "build"
33+
mv enscan-* build
34+
cd build || exit
35+
upx -9 ./*
36+
find . -type f -print0 | xargs -0 md5sum > md5.txt
37+
cat md5.txt
38+
# compress file (release)
39+
if [ "$1" == "release" ]; then
40+
mkdir compress
41+
mv md5.txt compress
42+
for i in `find . -type f -name "$appName-linux-*"`
43+
do
44+
tar -czvf compress/"$i".tar.gz "$i"
45+
done
46+
for i in `find . -type f -name "$appName-darwin-*"`
47+
do
48+
tar -czvf compress/"$i".tar.gz "$i"
49+
done
50+
for i in `find . -type f -name "$appName-windows-*"`
51+
do
52+
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
53+
done
54+
fi
55+
cd ../..

0 commit comments

Comments
 (0)