详见代码:
package main import ( "fmt" "net" ) for _, address := range addrs { // 检查 ip 地址判断是否回环地址 if ipnet, flag := address.(*net.IPNet); flag && !ipnet.IP.IsLoopback() { if ipnet.IP.To4() != nil { fmt.Println(ipnet.IP.String()) } } }
阳光部落原创,更多内容请访问http://www.sunbloger.com/