优化核心逻辑

This commit is contained in:
2025-01-08 14:52:14 +08:00
parent 172ccca162
commit b51d64644f
3 changed files with 35 additions and 12 deletions

27
main.go
View File

@@ -160,7 +160,7 @@ func runMainProcess() { // 主进程逻辑
IPSET_NUMBER = 0
IPSET_NAME = fmt.Sprintf("root%d", IPSET_NUMBER)
if return_value := IsIpset(IPSET_NAME); return_value == 1 {
if return_value := Is_Name_Ipset(IPSET_NAME); return_value == 1 {
createIPSet(IPSET_NAME)
}
@@ -183,16 +183,22 @@ func runMainProcess() { // 主进程逻辑
return 0
}())
if !strings.Contains(region, "中国") && !strings.Contains(region, "内网") {
if position, err := curl_(e1.Value.(net.IP).String()); err != nil { //判断地域
log.Printf("获取Ip地域出错: %v", err)
} else {
log.Printf("\033[31m%s %s\033[0m\n", e1.Value.(net.IP).String(), position) // 打印地域
AddIPSet(IPSET_NAME, e1.Value.(net.IP).String()) // 添加 Ip 到 ipset 集合
if Is_Ip_Ipset(e1.Value.(net.IP).String()) != 0 { // Ip不在 Ipset 集合中
if !strings.Contains(region, "中国") && !strings.Contains(region, "内网") { // 离线库判断不在中国内尝试API判断
if position, err := curl_(e1.Value.(net.IP).String()); err != nil { //API判断地域
log.Printf("获取Ip地域出错: %v", err)
} else {
log.Printf("\033[31m%s %s\033[0m\n", e1.Value.(net.IP).String(), position) // 打印地域
IpList.Remove(e1) // 移除第一个元素
AddIPSet(IPSET_NAME, e1.Value.(net.IP).String()) // 添加 Ip 到 ipset 集合
IpList.Remove(e1) // 移除第一个元素
}
} else { // 这时是国内地址
IpList.Remove(e1)
}
} else { // 这时是国内地址
} else { // 在 Ipset 集合中
log.Printf("\033[31m%s 已经在 Ipset 集合中\033[0m\n", e1.Value.(net.IP).String())
IpList.Remove(e1)
}
@@ -209,7 +215,6 @@ func runMainProcess() { // 主进程逻辑
go func() {
for {
if ipset_len, _ := NumIPSet(IPSET_NAME); ipset_len >= 65534 {
//log.Printf("ipset %s 列表已满 %dd\n", IPSET_NAME, ipset_len)
log.Printf("\033[31m ipset %s 列表已满 %d \033[0m\n", IPSET_NAME, ipset_len)
// 创建新的 ipset 集合
@@ -221,7 +226,7 @@ func runMainProcess() { // 主进程逻辑
}
IPSET_NAME = fmt.Sprintf("root%d", IPSET_NUMBER)
if return_value := IsIpset(IPSET_NAME); return_value == 1 {
if return_value := Is_Name_Ipset(IPSET_NAME); return_value == 1 {
createIPSet(IPSET_NAME)
}