github.com/bepass-org/wireguard-go@v1.0.4-rc2.0.20240304192354-ebce6572bc24/warp/endpoint.go (about) 1 package warp 2 3 import ( 4 "math/rand" 5 "net/netip" 6 "time" 7 ) 8 9 func WarpPrefixes() []netip.Prefix { 10 return []netip.Prefix{ 11 netip.MustParsePrefix("162.159.192.0/24"), 12 netip.MustParsePrefix("162.159.193.0/24"), 13 netip.MustParsePrefix("162.159.195.0/24"), 14 netip.MustParsePrefix("188.114.96.0/24"), 15 netip.MustParsePrefix("188.114.97.0/24"), 16 netip.MustParsePrefix("188.114.98.0/24"), 17 netip.MustParsePrefix("188.114.99.0/24"), 18 netip.MustParsePrefix("2606:4700:d0::/48"), 19 netip.MustParsePrefix("2606:4700:d1::/48"), 20 } 21 } 22 23 func RandomWarpEndpoint() (netip.AddrPort, error) { 24 ports := []int{500, 854, 859, 864, 878, 880, 890, 891, 894, 903, 908, 928, 934, 939, 942, 25 943, 945, 946, 955, 968, 987, 988, 1002, 1010, 1014, 1018, 1070, 1074, 1180, 1387, 1701, 26 1843, 2371, 2408, 2506, 3138, 3476, 3581, 3854, 4177, 4198, 4233, 4500, 5279, 27 5956, 7103, 7152, 7156, 7281, 7559, 8319, 8742, 8854, 8886} 28 29 // Seed the random number generator 30 rng := rand.New(rand.NewSource(time.Now().UnixNano())) 31 32 // Pick a random port number 33 randomPort := uint16(ports[rng.Intn(len(ports))]) 34 35 cidrs := WarpPrefixes() 36 37 randomIP, err := RandomIPFromPrefix(cidrs[rng.Intn(len(cidrs))]) 38 if err != nil { 39 return netip.AddrPort{}, err 40 } 41 42 return netip.AddrPortFrom(randomIP, randomPort), nil 43 }