通知内 IP 脱敏

This commit is contained in:
naiba
2021-05-27 20:48:12 +08:00
parent 06914eed99
commit 2b05dcfc23
9 changed files with 76 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/hex"
"math/rand"
"os"
"regexp"
"time"
"unsafe"
)
@@ -45,3 +46,21 @@ func MD5(plantext string) string {
func IsWindows() bool {
return os.PathSeparator == '\\' && os.PathListSeparator == ';'
}
var ipv4Re = regexp.MustCompile(`(\d*\.).*(\.\d*)`)
func ipv4Desensitize(ipv4Addr string) string {
return ipv4Re.ReplaceAllString(ipv4Addr, "$1****$2")
}
var ipv6Re = regexp.MustCompile(`(\w*:\w*:).*(:\w*:\w*)`)
func ipv6Desensitize(ipv6Addr string) string {
return ipv6Re.ReplaceAllString(ipv6Addr, "$1****$2")
}
func IPDesensitize(ipAddr string) string {
ipAddr = ipv4Desensitize(ipAddr)
ipAddr = ipv6Desensitize(ipAddr)
return ipAddr
}