辅助函数

This commit is contained in:
kercylan
2023-04-23 11:23:54 +08:00
parent 86e9e7400a
commit 165e99f08e
17 changed files with 618 additions and 1 deletions

18
utils/network/ip.go Normal file
View File

@@ -0,0 +1,18 @@
package network
import (
"net"
)
// IP 返回本机出站地址
func IP() (ip net.IP, err error) {
var conn net.Conn
conn, err = net.Dial("udp", "8.8.8.8:80")
if err != nil {
return
}
_ = conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
ip = localAddr.IP
return
}