optimize
This commit is contained in:
47
main.go
47
main.go
@@ -155,7 +155,14 @@ func runMainProcess() { // 主进程逻辑
|
||||
//fmt.Println(e1.Value) // 输出第一个元素
|
||||
|
||||
region, _ := ip2region(e1.Value.(net.IP).String())
|
||||
log.Printf("当前 Ipset 链 %s\n", SIG_NAME)
|
||||
|
||||
log.Printf("当前 Ipset 链 %s %d\n", SIG_NAME, func() int {
|
||||
_len, _err := NumIPSet(SIG_NAME)
|
||||
if _err == nil {
|
||||
return _len
|
||||
}
|
||||
return 0
|
||||
}())
|
||||
|
||||
if !strings.Contains(region, "中国") && !strings.Contains(region, "内网") {
|
||||
if position, err := curl_(e1.Value.(net.IP).String()); err != nil { //判断地域
|
||||
@@ -184,14 +191,14 @@ func runMainProcess() { // 主进程逻辑
|
||||
|
||||
for {
|
||||
|
||||
if ipset_len, _ := NumIPSet(SIG_NAME); ipset_len >= 100 {
|
||||
if ipset_len, _ := NumIPSet(SIG_NAME); ipset_len >= 65534 {
|
||||
log.Printf("ipset %s 列表已满 %dd\n", SIG_NAME, ipset_len)
|
||||
|
||||
// 创建新的 ipset 集合
|
||||
SIG++
|
||||
|
||||
if SIG >= MAX_SIG {
|
||||
log.Printf("已创建 %s 个集合!!!", MAX_SIG)
|
||||
log.Printf("已创建 %d 个集合!!!", MAX_SIG)
|
||||
}
|
||||
|
||||
SIG_NAME = fmt.Sprintf("root%d", SIG)
|
||||
@@ -219,7 +226,7 @@ func handleCmd() {
|
||||
outputFile = flag.String("o", "", "保存捕获数据的输出文件(可选)")
|
||||
flag.StringVar(&instruction, "s", "", "-s start 启动 Iptables 规则\n-s stop 停止 Iptables 规则")
|
||||
flag.BoolVar(&help, "h", false, "")
|
||||
flag.BoolVar(&help, "help", false, "display this message")
|
||||
flag.BoolVar(&help, "help", false, "帮助信息")
|
||||
flag.Parse()
|
||||
|
||||
if help {
|
||||
@@ -233,20 +240,26 @@ func handleCmd() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
switch instruction {
|
||||
case "start":
|
||||
fmt.Println("启动 Iptables 规则")
|
||||
for i := 0; i < MAX_SIG; i++ {
|
||||
_name := fmt.Sprintf("root%d", i)
|
||||
iptables(_name)
|
||||
}
|
||||
if instruction != "" {
|
||||
switch instruction {
|
||||
case "start":
|
||||
fmt.Println("启动 Iptables 规则")
|
||||
for i := 0; i < MAX_SIG; i++ {
|
||||
_name := fmt.Sprintf("root%d", i)
|
||||
iptables_add(_name)
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
case "stop":
|
||||
fmt.Println("停止 Iptables 规则")
|
||||
os.Exit(0)
|
||||
default:
|
||||
log.Fatalf("未知的操作: %s. 请使用 'start' 或 'stop'.", instruction)
|
||||
os.Exit(0)
|
||||
case "stop":
|
||||
fmt.Println("停止 Iptables 规则")
|
||||
for i := 0; i < MAX_SIG; i++ {
|
||||
_name := fmt.Sprintf("root%d", i)
|
||||
iptables_del(_name)
|
||||
}
|
||||
os.Exit(0)
|
||||
default:
|
||||
log.Fatalf("未知的操作: %s. 请使用 'start' 或 'stop'.", instruction)
|
||||
}
|
||||
}
|
||||
|
||||
if listInterfaces {
|
||||
|
||||
Reference in New Issue
Block a user