mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-11-03 03:31:58 +08:00
27 lines
512 B
Go
27 lines
512 B
Go
package domaintool
|
|
|
|
import "strings"
|
|
|
|
func MaskSubdomain(domain string) string {
|
|
// 分离域名和端口部分
|
|
parts := strings.Split(domain, ":")
|
|
host := parts[0]
|
|
port := ""
|
|
if len(parts) > 1 {
|
|
port = ":" + parts[1]
|
|
}
|
|
|
|
// 分割域名部分
|
|
subdomains := strings.Split(host, ".")
|
|
if len(subdomains) <= 2 {
|
|
// 如果只有根域名部分,直接返回
|
|
return domain
|
|
}
|
|
|
|
// 将第一段替换为 "*"
|
|
subdomains[0] = "*"
|
|
maskedHost := strings.Join(subdomains, ".")
|
|
|
|
return maskedHost + port
|
|
}
|