mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 21:29:02 +08:00
fix space after ip
This commit is contained in:
parent
0b2c1abfa6
commit
e69316b95d
@ -9,6 +9,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/zu1k/nali/internal/tools"
|
||||
|
||||
"github.com/zu1k/nali/constant"
|
||||
|
||||
"github.com/zu1k/nali/pkg/cdn"
|
||||
@ -57,7 +59,7 @@ func ReplaceCDNInString(str string) (result string) {
|
||||
if _, found := done[cname]; found {
|
||||
continue
|
||||
}
|
||||
result = strings.ReplaceAll(result, cname, fmt.Sprintf("%s [%s]", cname, name))
|
||||
result = tools.ReplaceAdd(result, cname, fmt.Sprintf("%s [%s]", cname, name))
|
||||
done[cname] = true
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,10 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/zu1k/nali/constant"
|
||||
"github.com/zu1k/nali/internal/ipdb"
|
||||
"github.com/zu1k/nali/internal/iptools"
|
||||
"github.com/zu1k/nali/internal/tools"
|
||||
geoip2 "github.com/zu1k/nali/pkg/geoip"
|
||||
"github.com/zu1k/nali/pkg/ipip"
|
||||
"github.com/zu1k/nali/pkg/qqwry"
|
||||
@ -45,10 +44,10 @@ func ParseIPs(ips []string) {
|
||||
db1 = nil
|
||||
}
|
||||
for _, ip := range ips {
|
||||
if iptools.ValidIP4(ip) {
|
||||
if tools.ValidIP4(ip) {
|
||||
result := db0.Find(ip)
|
||||
fmt.Println(formatResult(ip, result))
|
||||
} else if iptools.ValidIP6(ip) && db1 != nil {
|
||||
} else if tools.ValidIP6(ip) && db1 != nil {
|
||||
result := db1.Find(ip)
|
||||
fmt.Println(formatResult(ip, result))
|
||||
} else {
|
||||
@ -67,16 +66,16 @@ func ReplaceIPInString(str string) (result string) {
|
||||
}
|
||||
|
||||
result = str
|
||||
ip4s := iptools.GetIP4FromString(str)
|
||||
ip4s := tools.GetIP4FromString(str)
|
||||
for _, ip := range ip4s {
|
||||
info := db0.Find(ip)
|
||||
result = strings.ReplaceAll(result, ip, formatResult(ip, info))
|
||||
result = tools.ReplaceAdd(result, ip, formatResult(ip, info))
|
||||
}
|
||||
|
||||
ip6s := iptools.GetIP6FromString(str)
|
||||
ip6s := tools.GetIP6FromString(str)
|
||||
for _, ip := range ip6s {
|
||||
info := db1.Find(ip)
|
||||
result = strings.ReplaceAll(result, ip, formatResult(ip, info))
|
||||
result = tools.ReplaceAdd(result, ip, formatResult(ip, info))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package iptools
|
||||
package tools
|
||||
|
||||
import (
|
||||
"regexp"
|
@ -1,4 +1,4 @@
|
||||
package iptools
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
12
internal/tools/replace.go
Normal file
12
internal/tools/replace.go
Normal file
@ -0,0 +1,12 @@
|
||||
package tools
|
||||
|
||||
import "strings"
|
||||
|
||||
func ReplaceAdd(origin string, old string, new string) string {
|
||||
subLen := len(new) - len(old)
|
||||
wanted := old + strings.Repeat(" ", subLen)
|
||||
if strings.Contains(origin, wanted) {
|
||||
return strings.ReplaceAll(origin, wanted, new)
|
||||
}
|
||||
return strings.ReplaceAll(origin, old, new)
|
||||
}
|
@ -109,6 +109,9 @@ func (db QQwry) Find(ip string) (res string) {
|
||||
country = strings.ReplaceAll(country, " CZ88.NET", "")
|
||||
area = strings.ReplaceAll(area, " CZ88.NET", "")
|
||||
|
||||
if area == "" {
|
||||
return country
|
||||
}
|
||||
return fmt.Sprintf("%s %s", country, area)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user