mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 05:56:46 +08:00

- 重命名 Common -> common,WebScan -> webscan,遵循 Go 包命名约定 - 修复模块路径大小写不匹配导致的编译错误 - 清理依赖项,优化 go.mod 文件 - 添加 Docker 测试环境配置文件 - 新增镜像拉取脚本以处理网络超时问题 - 成功编译生成 fscan v2.2.1 可执行文件 该修复解决了 Linux 系统下包名大小写敏感导致的模块解析失败问题。
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// HostInfoHelper 提供HostInfo的辅助方法
|
|
// 使用函数而不是方法,保持向后兼容
|
|
|
|
|
|
// GetPort 获取端口号(转换为整数)
|
|
func GetPort(h *HostInfo) (int, error) {
|
|
if h.Ports == "" {
|
|
return 0, fmt.Errorf("端口未设置")
|
|
}
|
|
return strconv.Atoi(h.Ports)
|
|
}
|
|
|
|
|
|
// IsWebTarget 判断是否为Web目标
|
|
func IsWebTarget(h *HostInfo) bool {
|
|
return h.Url != ""
|
|
}
|
|
|
|
// HasPort 检查是否设置了端口
|
|
func HasPort(h *HostInfo) bool {
|
|
return h.Ports != ""
|
|
}
|
|
|
|
// ValidateHostInfo 验证HostInfo的有效性
|
|
func ValidateHostInfo(h *HostInfo) error {
|
|
if h.Host == "" && h.Url == "" {
|
|
return fmt.Errorf("主机地址或URL必须至少指定一个")
|
|
}
|
|
|
|
// 验证端口格式(如果指定了)
|
|
if h.Ports != "" {
|
|
if _, err := GetPort(h); err != nil {
|
|
return fmt.Errorf("端口格式无效: %v", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// HostInfoString 返回HostInfo的字符串表示
|
|
func HostInfoString(h *HostInfo) string {
|
|
if IsWebTarget(h) {
|
|
return h.Url
|
|
}
|
|
|
|
if HasPort(h) {
|
|
return fmt.Sprintf("%s:%s", h.Host, h.Ports)
|
|
}
|
|
|
|
return h.Host
|
|
} |