golang 获取本地ip

前端之家收集整理的这篇文章主要介绍了golang 获取本地ip前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package main

import (
	"fmt"
	"net"
	"strings"
)

func main() {
	conn,err := net.Dial("udp","www.google.com.hk:80")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer conn.Close()
	fmt.Println(conn.LocalAddr().String())
	//fmt.Println(strings.Split(conn.LocalAddr().String(),":")[0])
}
原文链接:https://www.f2er.com/go/191284.html

猜你在找的Go相关文章