I'm currently attempting to learn the programming language go and stubbled across this weird problem. I've created a simple go application that gets the Hostname succesfully, which I then try to get my addresses with. Finally I iterate over these addresses.
package main
import (
"fmt"
"net"
"os"
"strconv"
)
func main() {
name, error := os.Hostname()
fmt.Println("Name: " + name)
fmt.Print("Error: ")
fmt.Println(error)
addrs, err := net.LookupHost(name)
fmt.Println(addrs)
fmt.Println(err)
for indx, addr := range addrs {
fmt.Println("Address number " + strconv.Itoa(indx) + ": " + addr)
}
}
The output of this is the following:
Name: My-macbook.local
Error: <nil>
[]
lookup My-macbook.local: no such host
I also tried using net.LookUpIP(name), which resulted in the same. I'm connected to the internet and I checked that I had an ip address in system preferences -> network. I am currently on a Macbook Pro with macOS Sierra.
My friend ran the exact same code with the exact same version of go and had two addresses returned so do I have something preventing me from seeing my Ip addresses. Has anyone experienced this before?