mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
@@ -3,6 +3,7 @@ package netx
|
||||
import (
|
||||
"mayfly-go/pkg/logx"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
)
|
||||
@@ -68,3 +69,13 @@ func Ip2Region(ip string) string {
|
||||
}
|
||||
return region
|
||||
}
|
||||
|
||||
func GetOutBoundIP() string {
|
||||
conn, err := net.Dial("udp", "8.8.8.8:53")
|
||||
if err != nil {
|
||||
return "0.0.0.0"
|
||||
}
|
||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||
ip := strings.Split(localAddr.String(), ":")[0]
|
||||
return ip
|
||||
}
|
||||
|
||||
10
server/pkg/utils/netx/netx_test.go
Normal file
10
server/pkg/utils/netx/netx_test.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package netx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIp(t *testing.T) {
|
||||
fmt.Println(GetOutBoundIP())
|
||||
}
|
||||
Reference in New Issue
Block a user