1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-24 06:09:01 +08:00
nali/internal/tools/replace.go

24 lines
909 B
Go
Raw Normal View History

2020-07-21 17:23:38 +08:00
package tools
2020-07-21 17:54:57 +08:00
import (
"strings"
"regexp"
2020-07-21 17:54:57 +08:00
)
2020-07-21 17:23:38 +08:00
func AddInfoIp4(origin string, ip string, info string) (result string) {
re := regexp.MustCompile("(^|[^0-9.])(" + strings.ReplaceAll(ip, ".", "\\.") + ")($|[^0-9.])")
result = re.ReplaceAllString(origin, "$1$2"+" ["+info+"]$3")
2020-07-21 17:54:57 +08:00
return strings.TrimRight(result, " \t")
2020-07-21 17:23:38 +08:00
}
func AddInfoIp6(origin string, ip string, info string) (result string) {
re := regexp.MustCompile("(^|[^0-9a-fA-F:])(" + strings.ReplaceAll(ip, ".", "\\.") + ")($|[^0-9a-fA-F:])")
result = re.ReplaceAllString(origin, "$1$2"+" ["+info+"]$3")
return strings.TrimRight(result, " \t")
}
func AddInfoDomain(origin string, domain string, info string) (result string) {
re := regexp.MustCompile("(^|[^0-9a-zA-Z-])(" + strings.ReplaceAll(domain, ".", "\\.") + ")($|[^0-9a-zA-Z-\\.])")
result = re.ReplaceAllString(origin, "$1$2"+" ["+info+"]$3")
return strings.TrimRight(result, " \t")
}