golang 获取ip代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

package main
 
import (
    "fmt"
    "net"
    "strings"
)
 
func main() {
    conn, err := net.Dial("udp", "google.com:80")
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    defer conn.Close()
    fmt.Println(strings.Split(conn.LocalAddr().String(), ":")[0])
}