I want to get the computer\'s IP address. I used the code below, but it returns 127.0.0.1.
127.0.0.1
I want to get the IP address, such as 10.32.10.111
10.32.10.111
This worked for me:
host, _ := os.Hostname() addrs, _ := net.LookupIP(host) for _, addr := range addrs { if ipv4 := addr.To4(); ipv4 != nil { fmt.Println("IPv4: ", ipv4) } }
Unlike the poster's example, it returns only non-loopback addresses, e.g. 10.120.X.X.