diff --git a/pro/comm.go b/pro/comm.go index dc10001..ec1f661 100644 --- a/pro/comm.go +++ b/pro/comm.go @@ -141,9 +141,19 @@ func RedisDel() { m_redis_db.Del(m_md5_tun_key) } +func GetUDPLocalIPPort(level string) (string, int) { + conn, err := net.Dial(level, "ifconfig.co:80") + if err != nil { + return "", 0 + } + defer conn.Close() + + return conn.LocalAddr().(*net.UDPAddr).IP.String(), conn.LocalAddr().(*net.UDPAddr).Port +} + func GetUDPAddr() (conn *net.UDPConn, addr tun.AddrType) { - addr.LocalIPv4, _ = utils.GetUDPLocalIPPort("udp4") - addr.IPv6, _ = utils.GetUDPLocalIPPort("udp6") + addr.LocalIPv4, _ = GetUDPLocalIPPort("udp4") + addr.IPv6, _ = GetUDPLocalIPPort("udp6") var err error diff --git a/pro/local.go b/pro/local.go index da61ad8..7509e15 100644 --- a/pro/local.go +++ b/pro/local.go @@ -23,7 +23,7 @@ func GetLocalQuicConn(conn *net.UDPConn, addr *tun.AddrType, count int) (*tun.Tu var tun_active *tun.TunActive var tun_passive *tun.TunPassive - SessionID := string(utils.RandomBytes(24)) + SessionID := string(go2.RandomBytes(24)) utils.Log().DebugF("会话ID: %s", SessionID) redisJson := RedisJsonType{ diff --git a/ui2/ui.go b/ui2/ui.go index 82d7bc0..6bdee95 100644 --- a/ui2/ui.go +++ b/ui2/ui.go @@ -10,7 +10,6 @@ import ( "goodlink/config" "goodlink/pro" _ "goodlink/pro" - "goodlink/utils" _ "embed" _ "net/http/pprof" @@ -47,7 +46,7 @@ func GetMainUI(myWindow *fyne.Window) *fyne.Container { } m_button_key_create = widget.NewButton("生成密钥", func() { - m_validated_key.SetText(string(utils.RandomBytes(24))) + m_validated_key.SetText(string(go2.RandomBytes(24))) }) key_copy_button := widget.NewButton("复制密钥", func() { clipboard.WriteAll(m_validated_key.Text) diff --git a/utils/net.go b/utils/net.go deleted file mode 100644 index e517e8f..0000000 --- a/utils/net.go +++ /dev/null @@ -1,51 +0,0 @@ -package utils - -import ( - "crypto/tls" - "io" - "net" - "net/http" - "strconv" - "strings" - "time" -) - -func GetUDPLocalIPPort(level string) (string, int) { - conn, err := net.Dial(level, "ifconfig.co:80") - if err != nil { - return "", 0 - } - defer conn.Close() - - return conn.LocalAddr().(*net.UDPAddr).IP.String(), conn.LocalAddr().(*net.UDPAddr).Port -} - -func GetTCPWanIPv4Port(dialer *net.Dialer) (string, int) { - var res []byte - var err error - var resp *http.Response - - client := &http.Client{ - Transport: &http.Transport{ - DialContext: dialer.DialContext, - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, // 跳过证书验证 - }, - }, - Timeout: 3 * time.Second, - } - if resp, err = client.Get("https://goodlink.kony.vip/ip"); err != nil { - return "", 0 - } - defer resp.Body.Close() - - if res, err = io.ReadAll(resp.Body); err != nil { - return "", 0 - } - - localAddr := string(res) - - ip := strings.Split(localAddr, ":")[0] - port, _ := strconv.Atoi(strings.Split(localAddr, ":")[1]) - return ip, port -} diff --git a/utils/tools.go b/utils/tools.go deleted file mode 100644 index 87c7ab0..0000000 --- a/utils/tools.go +++ /dev/null @@ -1,20 +0,0 @@ -package utils - -import ( - "crypto/rand" - "math/big" -) - -func RandomBytes(length int) []byte { - bytes := make([]byte, length) - charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - for i := 0; i < length; { - bint, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset)))) - if err != nil { - return nil - } - bytes[i] = charset[bint.Int64()] - i++ - } - return bytes -}