feat: add subscriber type

This commit is contained in:
langhuihui
2024-12-18 13:23:10 +08:00
parent 0042568dff
commit 6037cbe18d
19 changed files with 1309 additions and 722 deletions

View File

@@ -279,12 +279,14 @@ var ipReg = regexp.MustCompile(`^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(2
var privateIPReg = regexp.MustCompile(`^((10|192\.168|172\.(1[6-9]|2[0-9]|3[0-1]))\.){3}(10|192\.168|172\.(1[6-9]|2[0-9]|3[0-1]))$`)
var routes map[string]string
var PublicIP string
func IsPrivateIP(ip string) bool {
return privateIPReg.MatchString(ip)
}
func initRoutes() {
PublicIP = myip.ExternalIP()
for k, v := range myip.LocalAndInternalIPs() {
routes[k] = v
if lastdot := strings.LastIndex(k, "."); lastdot >= 0 {
@@ -304,6 +306,9 @@ func init() {
func GetPublicIP(ip string) string {
initRoutesWait.Wait()
if ip == "" {
return PublicIP
}
if publicIP, ok := routes[ip]; ok {
return publicIP
}