mirror of https://github.com/v2ray/v2ray-core
Update chinaip generator
parent
9d51bd2985
commit
6afeaccc5a
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
APNIC_FILE="http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest"
|
|
||||||
curl "${APNIC_FILE}" | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > ipv4.txt
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,31 +3,49 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"net/http"
|
||||||
"path/filepath"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
apnicFile = "http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
GOPATH := os.Getenv("GOPATH")
|
resp, err := http.Get(apnicFile)
|
||||||
src := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "tools", "chinaip", "ipv4.txt")
|
|
||||||
reader, err := os.Open(src)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ipNet := v2net.NewIPNet()
|
if resp.StatusCode != 200 {
|
||||||
|
panic(fmt.Errorf("Unexpected status %d", resp.StatusCode))
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(reader)
|
ipNet := v2net.NewIPNet()
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if len(line) == 0 {
|
parts := strings.Split(line, "|")
|
||||||
break
|
if len(parts) < 5 {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
_, t, err := net.ParseCIDR(line)
|
if strings.ToLower(parts[1]) != "cn" || strings.ToLower(parts[2]) != "ipv4" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ip := parts[3]
|
||||||
|
count, err := strconv.Atoi(parts[4])
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
mask := 32 - int(math.Floor(math.Log2(float64(count))+0.5))
|
||||||
|
cidr := fmt.Sprintf("%s/%d", ip, mask)
|
||||||
|
_, t, err := net.ParseCIDR(cidr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue