(ipList []string)
| 595 | } |
| 596 | |
| 597 | func getRandomIPv6s(ipList []string) []string { |
| 598 | var randomIPs []string |
| 599 | for _, subnet := range ipList { |
| 600 | subnet = strings.TrimSpace(subnet) |
| 601 | if subnet == "" { |
| 602 | continue |
| 603 | } |
| 604 | if idx := strings.Index(subnet, "/"); idx >= 0 { |
| 605 | subnet = subnet[:idx] |
| 606 | } |
| 607 | // 展开 :: 压缩,确保有 8 段 |
| 608 | if strings.Contains(subnet, "::") { |
| 609 | parts := strings.Split(subnet, "::") |
| 610 | left := strings.Split(parts[0], ":") |
| 611 | var right []string |
| 612 | if len(parts) > 1 && parts[1] != "" { |
| 613 | right = strings.Split(parts[1], ":") |
| 614 | } |
| 615 | missing := 8 - len(left) - len(right) |
| 616 | sections := left |
| 617 | for range missing { |
| 618 | sections = append(sections, "0") |
| 619 | } |
| 620 | sections = append(sections, right...) |
| 621 | subnet = strings.Join(sections, ":") |
| 622 | } |
| 623 | sections := strings.Split(subnet, ":") |
| 624 | if len(sections) >= 3 { |
| 625 | sections = sections[:3] |
| 626 | for i := 3; i < 8; i++ { |
| 627 | sections = append(sections, fmt.Sprintf("%x", nextRandomIntn(65536))) |
| 628 | } |
| 629 | randomIPs = append(randomIPs, strings.Join(sections, ":")) |
| 630 | } |
| 631 | } |
| 632 | return randomIPs |
| 633 | } |
| 634 | |
| 635 | // downloadAllData 确保所有数据文件存在,缺失则自动下载 |
| 636 | func downloadAllData() { |
no test coverage detected