new: add auto warp option
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/netip"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -124,18 +125,50 @@ func parsePeerConfig(peerConfig *PeerConfig, line string) {
|
||||
peerConfig.Endpoint = strings.TrimSpace(strings.SplitN(line, "=", 2)[1])
|
||||
}
|
||||
}
|
||||
|
||||
var warpIPList = []string{
|
||||
"162.159.192.0/24",
|
||||
"162.159.193.0/24",
|
||||
"162.159.195.0/24",
|
||||
"162.159.204.0/24",
|
||||
"188.114.96.0/24",
|
||||
"188.114.97.0/24",
|
||||
"188.114.98.0/24",
|
||||
"188.114.99.0/24",
|
||||
}
|
||||
var warpPorts = []uint16{500, 854, 859, 864, 878, 880, 890, 891, 894, 903, 908, 928, 934, 939, 942,
|
||||
943, 945, 946, 955, 968, 987, 988, 1002, 1010, 1014, 1018, 1070, 1074, 1180, 1387, 1701,
|
||||
1843, 2371, 2408, 2506, 3138, 3476, 3581, 3854, 4177, 4198, 4233, 4500, 5279,
|
||||
5956, 7103, 7152, 7156, 7281, 7559, 8319, 8742, 8854, 8886}
|
||||
|
||||
func getRandomIP() string {
|
||||
randomRange := warpIPList[rand.Intn(len(warpIPList))]
|
||||
|
||||
ip, err := warp.RandomIPFromRange(randomRange)
|
||||
if err == nil {
|
||||
ip.String()
|
||||
}
|
||||
return "engage.cloudflareclient.com"
|
||||
}
|
||||
|
||||
func generateRandomPort() uint16 {
|
||||
return warpPorts[rand.Intn(len(warpPorts))]
|
||||
}
|
||||
|
||||
func generateWarp(license string, host string, port uint16) (*T.Outbound, error) {
|
||||
if host == "" {
|
||||
host = "engage.cloudflareclient.com"
|
||||
host = "auto"
|
||||
}
|
||||
if host == "default" || host == "random" || host == "auto" {
|
||||
host = getRandomIP()
|
||||
}
|
||||
if port == 0 {
|
||||
port = 2408
|
||||
port = generateRandomPort()
|
||||
}
|
||||
endpoint := fmt.Sprint("%s:%p", host, port)
|
||||
|
||||
if !warp.CheckProfileExists(license) {
|
||||
fmt.Printf("profile s not exit! ---%s---", license)
|
||||
err := warp.LoadOrCreateIdentity(license, endpoint)
|
||||
err := warp.LoadOrCreateIdentity(license)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -148,6 +181,9 @@ func generateWarp(license string, host string, port uint16) (*T.Outbound, error)
|
||||
}
|
||||
// fmt.Printf("%v", wgConfig)
|
||||
singboxConfig, err := wireGuardToSingbox(wgConfig, host, port)
|
||||
if host == "auto" && singboxConfig.WireGuardOptions.FakePackets == "" {
|
||||
singboxConfig.WireGuardOptions.FakePackets = "5-10"
|
||||
}
|
||||
singboxJSON, err := json.MarshalIndent(singboxConfig, "", " ")
|
||||
if err != nil {
|
||||
fmt.Println("Error marshaling Singbox configuration:", err)
|
||||
|
||||
4
go.mod
4
go.mod
@@ -3,13 +3,13 @@ module github.com/hiddify/libcore
|
||||
go 1.21.5
|
||||
|
||||
require (
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125201255-2626ecb3c77a
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126122154-854054f22383
|
||||
github.com/sagernet/gomobile v0.1.1
|
||||
github.com/sagernet/sing v0.3.0
|
||||
github.com/sagernet/sing-box v1.8.2
|
||||
github.com/sagernet/sing-dns v0.1.12
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/uoosef/wireguard-go v0.0.2-alpha.0.20240125181720-5dea742f6614
|
||||
github.com/uoosef/wireguard-go v0.0.3-alpha.0.20240126073448-28658ac4c921
|
||||
github.com/xmdhs/clash2singbox v0.0.2
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
8
go.sum
8
go.sum
@@ -51,8 +51,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
|
||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125210314-493067cd2d66 h1:1soOFv4mdCq9OiRN4eo4B0ylDY1EeSnl0M7szOTYNz4=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125210314-493067cd2d66/go.mod h1:DnlHl/vlinL9Mn95+qJ3RzgE3E/9pWlAvTsauo7F5HM=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125201255-2626ecb3c77a h1:afDHoio+CpOc80Q83ykKsX+aHUQB3BGYj0f3bNybWHs=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125201255-2626ecb3c77a/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126122154-854054f22383 h1:yFWzs/DLEXpcdXaVFFEQBHz2Q6XQ+j/IqXC/Qzm7dGw=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126122154-854054f22383/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
@@ -181,8 +181,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 h1:tHNk7XK9GkmKUR6Gh8gVBKXc2MVSZ4G/NnWLtzw4gNA=
|
||||
github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923/go.mod h1:eLL9Nub3yfAho7qB0MzZizFhTU2QkLeoVsWdHtDW264=
|
||||
github.com/uoosef/wireguard-go v0.0.2-alpha.0.20240125181720-5dea742f6614 h1:HE/PjVFuqVgC4MLAadoUSGAmxAj+jns4CSVBUO6RND0=
|
||||
github.com/uoosef/wireguard-go v0.0.2-alpha.0.20240125181720-5dea742f6614/go.mod h1:uEnuKQ/PHpFdYwftT4bzwI8F3d2l9zsWZ9iDbLBIm0c=
|
||||
github.com/uoosef/wireguard-go v0.0.3-alpha.0.20240126073448-28658ac4c921 h1:v7TBzuJQJYJh5Ynf/R3dY2yr10Ti/uHpW6l8yRI8fhc=
|
||||
github.com/uoosef/wireguard-go v0.0.3-alpha.0.20240126073448-28658ac4c921/go.mod h1:uEnuKQ/PHpFdYwftT4bzwI8F3d2l9zsWZ9iDbLBIm0c=
|
||||
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg=
|
||||
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
|
||||
github.com/xmdhs/clash2singbox v0.0.2 h1:/gxaFm8fmv+UcUZzK508Z0yR01wg1LHrrq872Qibk1I=
|
||||
|
||||
Reference in New Issue
Block a user