feat(config): 添加服务器端口获取功能

添加GetPort方法用于获取服务器当前IP和端口信息,
新增Name和Owner字段到ServerList模型中

refactor(login): 优化调试参数处理

将命令行参数解析改为使用parser.GetOpt获取debug选项,
移除未使用的fmt和qqwry导入包

refactor(main): 清理示例代码

移除main.go中的
This commit is contained in:
2026-01-04 00:16:49 +08:00
parent 77baefef11
commit 808612cc1e
6 changed files with 37 additions and 26 deletions

View File

@@ -21,8 +21,8 @@ var (
Brief: "start http server",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
// g.Dump(g.DB("test").GetConfig())
r := parser.GetArgAll()
if len(r) > 1 {
r := parser.GetOpt("debug", false)
if r.Bool() {
g.DB().SetDebug(true)
}
if cool.IsRedisMode {

View File

@@ -1,10 +1,7 @@
package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/xiaoqidun/qqwry"
"golang.org/x/crypto/bcrypt"
"blazing/common/data/xmlres"
@@ -31,26 +28,14 @@ func init() {
}
func main() {
// 示例调用
// 要查询的 IP可替换为任意 IPv4/IPv6
targetIP := "58.252.115.112"
// 输出格式(支持 plain/xml/json/jsonp/php/csv/serialized默认 json
outputFormat := "json"
// 执行查询
result, err := qqwry.LookupIP(targetIP, outputFormat)
if err != nil {
fmt.Printf("查询出错: %v\n", err)
return
}
// 打印结果
fmt.Println("IP 定位结果:")
fmt.Printf("IP 地址: %s\n", result.IP)
fmt.Printf("IP 版本: %d\n", result.IPVersion)
fmt.Printf("国家: %s (%s)\n", result.CountryName, result.CountryCode2)
fmt.Printf("服务商: %s\n", result.ISP)
fmt.Printf("响应状态: %s (%s)\n", result.ResponseMessage, result.ResponseCode)
// // 打印结果
// fmt.Println("IP 定位结果:")
// fmt.Printf("IP 地址: %s\n", result.IP)
// fmt.Printf("IP 版本: %d\n", result.IPVersion)
// fmt.Printf("国家: %s (%s)\n", result.CountryName, result.CountryCode2)
// fmt.Printf("服务商: %s\n", result.ISP)
// fmt.Printf("响应状态: %s (%s)\n", result.ResponseMessage, result.ResponseCode)
// ip := "103.236.78.60"
// sshPort := "50799"
// user := "root"

View File

@@ -7,6 +7,7 @@ import (
v1 "blazing/modules/base/api/v1"
"blazing/modules/base/service"
config "blazing/modules/config/service"
"github.com/gogf/gf/v2/frame/g"
)
@@ -80,3 +81,16 @@ func (c *BaseOpen) RefreshToken(ctx context.Context, req *RefreshTokenReq) (res
res = cool.Ok(data)
return
}
// 获取服务器当前ip和端口
type GetPortReq struct {
g.Meta `path:"/getport" method:"GET"`
}
func (c *BaseOpen) GetPort(ctx context.Context, req *GetPortReq) (res *cool.BaseRes, err error) {
res = &cool.BaseRes{}
res.Data = config.NewServerService().GetPort()
return
}

View File

@@ -46,6 +46,7 @@ func (s *BaseSysLogService) Record(ctx g.Ctx) {
baseSysLog.UserID = admin.UserId
baseSysLog.Action = r.Method + ":" + r.URL.Path
baseSysLog.IP = r.GetClientIp()
// 从内存或缓存查询IP
location, err := qqwry.QueryIP(baseSysLog.IP)
if err != nil {

View File

@@ -19,8 +19,12 @@ type ServerList struct {
//服务器异色概率设定ServerList
ShinyRate uint8 `gorm:"default:0;comment:'异色概率'" json:"shiny_rate"`
//服务器天气设定ServerList
WeatherRate uint8 `gorm:"default:0;comment:'天气概率'" json:"weather_rate"`
Desc string `gorm:"comment:'服务器描述'" json:"desc"`
WeatherRate uint8 `gorm:"default:0;comment:'天气概率'" json:"weather_rate"`
//服务器名称Desc
Name string `gorm:"comment:'服务器名称'" json:"name"`
//服务器属主Desc
Owner uint32 `gorm:"comment:'服务器属主'" json:"owner"`
Desc string `gorm:"comment:'服务器描述'" json:"desc"`
}
// TableName ServerList's table name

View File

@@ -21,6 +21,13 @@ func NewServerService() *ServerService {
},
}
}
func (s *ServerService) GetPort() []model.ServerList {
var item []model.ServerList
cool.DBM(s.Model).Fields("ip", "port").Scan(&item)
return item
}
// RemoteExecuteScript 远程执行脚本并实时显示输出
// ip: 服务器IP