diff --git a/core/cdn/cdn.go b/core/cdn/cdn.go index 2d5344b..7c219c8 100644 --- a/core/cdn/cdn.go +++ b/core/cdn/cdn.go @@ -3,15 +3,18 @@ package cdn import ( "kscan/core/slog" "kscan/lib/qqwry" + "os" + "path/filepath" "strings" ) var database *qqwry.QQwry -const filename = "./qqwry.dat" +var filename = "qqwry.dat" +var path = getRealPath() func Init() { - d, err := qqwry.NewQQwry(filename) + d, err := qqwry.NewQQwry(GetPath()) if err != nil { slog.Println(slog.WARN, "qqwry init err:", err) return @@ -19,8 +22,12 @@ func Init() { database = d } +func GetPath() string { + return path + "/" + filename +} + func DownloadQQWry() error { - return qqwry.Download(filename) + return qqwry.Download(GetPath()) } func FindCDN(query string) (bool, string, error) { @@ -38,3 +45,9 @@ func Find(query string) (string, error) { } return result.String(), err } + +func getRealPath() string { + dir, _ := os.Executable() + path := filepath.Dir(dir) + return path +} diff --git a/kscan.go b/kscan.go index 2626d97..1178e47 100644 --- a/kscan.go +++ b/kscan.go @@ -238,7 +238,7 @@ func InitKscan() { gonmap.InitAppBannerDiscernConfig(app.Setting.Host, app.Setting.Path, app.Setting.Proxy, app.Setting.Timeout) //CDN检测初始化 if app.Setting.CloseCDN == false { - if misc.FileIsExist("./qqwry.dat") == false { + if misc.FileIsExist(cdn.GetPath()) == false { slog.Printf(slog.WARN, "未检测到qqwry.dat,将关闭CDN检测功能,如需开启,请执行kscan --download-qqwry下载该文件") app.Setting.CloseCDN = true } else {