diff --git a/cmd/skywire-cli/commands/node/gen-config.go b/cmd/skywire-cli/commands/node/gen-config.go index b2f2a0e126..e24dbb0d43 100644 --- a/cmd/skywire-cli/commands/node/gen-config.go +++ b/cmd/skywire-cli/commands/node/gen-config.go @@ -1,7 +1,9 @@ package node import ( + "errors" "fmt" + "net" "path/filepath" "time" @@ -84,6 +86,13 @@ func defaultConfig() *visor.Config { conf.Node.StaticPubKey = pk conf.Node.StaticSecKey = sk + lIPaddr, err := getLocalIPAddress() + if err != nil { + log.Warn(err) + } + + conf.STCP.LocalAddr = lIPaddr + if testenv { conf.Messaging.Discovery = skyenv.TestDmsgDiscAddr } else { @@ -184,3 +193,19 @@ func defaultSkysocksClientConfig() visor.AppConfig { Port: routing.Port(skyenv.SkysocksClientPort), } } + +func getLocalIPAddress() (string, error) { + addrs, err := net.InterfaceAddrs() + if err != nil { + return "", err + } + + for _, a := range addrs { + if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { + if ipnet.IP.To4() != nil { + return ipnet.IP.String() + ":7777", nil + } + } + } + return "", errors.New("could not find local IP address") +}