Skip to content

Commit b43f49f

Browse files
committed
增加配置文件
1 parent ab2b09b commit b43f49f

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

common/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ var ScanTypeKeys = map[string]string{
199199
type ENConfig struct {
200200
Version float64 `yaml:"version"`
201201
UserAgent string `yaml:"user_agent"` // 自定义 User-Agent
202-
Cookies struct {
202+
Api struct {
203+
Api string `yaml:"api"`
204+
Mcp string `yaml:"mcp"`
205+
}
206+
Cookies struct {
203207
Aldzs string `yaml:"aldzs"`
204208
Xlb string `yaml:"xlb"`
205209
Aiqicha string `yaml:"aiqicha"`
@@ -221,11 +225,14 @@ type ENConfig struct {
221225
}
222226

223227
var cfgYName = filepath.Join(utils.GetConfigPath(), "config.yaml")
224-
var cfgYV = 0.6
225-
var configYaml = `version: 0.6
228+
var cfgYV = 0.7
229+
var configYaml = `version: 0.7
226230
user_agent: "" # 自定义 User-Agent(可设置为获取Cookie的浏览器)
227231
app:
228232
miit_api: '' # HG-ha的ICP_Query (非狼组维护 https://github.com/HG-ha/ICP_Query)
233+
api:
234+
api: ':31000' # API监听地址
235+
mcp: 'http://localhost:8080' # MCP SSE监听地址
229236
cookies:
230237
aiqicha: '' # 爱企查 Cookie
231238
tianyancha: '' # 天眼查 Cookie

common/utils/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"math"
1313
"math/big"
1414
mrand "math/rand"
15+
"net"
16+
"net/url"
1517
"os"
1618
"path/filepath"
1719
"regexp"
@@ -268,3 +270,18 @@ func RandomElement(c string) string {
268270
// 返回该索引对应的元素
269271
return slice[index]
270272
}
273+
274+
func ExtractPortString(rawURL string) (string, error) {
275+
// 解析 URL
276+
u, err := url.Parse(rawURL)
277+
if err != nil {
278+
return "", fmt.Errorf("无效的 URL: %v", err)
279+
}
280+
// 提取 host:port 部分
281+
_, port, err := net.SplitHostPort(u.Host)
282+
if err != nil {
283+
return "", fmt.Errorf("未指定端口且协议 %q 无默认端口", u.Scheme)
284+
}
285+
286+
return port, nil // port 已经是字符串
287+
}

runner/api.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func api(options *common.ENOptions) {
4040
if data, ok := enApiData[w.OrgName]; !ok || w.IsRefresh {
4141
enApiStatus[w.OrgName] = true
4242
rdata = enTask.getInfoByApi(w)
43-
fmt.Println(rdata)
4443
message = "查询成功"
4544
enApiStatus[w.OrgName] = false
4645
enApiData[w.OrgName] = rdata
@@ -88,7 +87,7 @@ func api(options *common.ENOptions) {
8887

8988
}
9089
enTask.StartENWorkers()
91-
err := r.Run(":31000")
90+
err := r.Run(options.ENConfig.Api.Api)
9291
if err != nil {
9392
gologger.Error().Msgf("API服务启动失败!")
9493
gologger.Fatal().Msgf(err.Error())

runner/mcpServer.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/mark3labs/mcp-go/server"
88
"github.com/wgpsec/ENScan/common"
99
"github.com/wgpsec/ENScan/common/gologger"
10+
"github.com/wgpsec/ENScan/common/utils"
1011
"golang.org/x/net/context"
1112
"log"
1213
"strconv"
@@ -179,9 +180,14 @@ func McpServer(options *common.ENOptions) {
179180
),
180181
), getInfoByKeyword(enTask))
181182
enTask.StartENWorkers()
182-
sseServer := server.NewSSEServer(s, server.WithBaseURL("http://localhost:8080"))
183-
gologger.Info().Msgf("SSE server listening on :8080")
184-
if err := sseServer.Start(":8080"); err != nil {
183+
sseServer := server.NewSSEServer(s, server.WithBaseURL(options.ENConfig.Api.Mcp))
184+
port, err := utils.ExtractPortString(options.ENConfig.Api.Mcp)
185+
if err != nil {
186+
gologger.Error().Msgf("MCP服务启动失败!")
187+
gologger.Fatal().Msgf(err.Error())
188+
}
189+
gologger.Info().Msgf("SSE server listening on :" + port)
190+
if err := sseServer.Start(":" + port); err != nil {
185191
log.Fatalf("Server error: %v", err)
186192
}
187193
}

0 commit comments

Comments
 (0)