From 0ae06e0db10973a6987ccdc9793b083974e61783 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 29 Aug 2021 23:04:56 -0500 Subject: [PATCH] choose default route ip --- src/toolchain.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/toolchain.go b/src/toolchain.go index 19e7f3c..bcd1f8a 100644 --- a/src/toolchain.go +++ b/src/toolchain.go @@ -295,6 +295,13 @@ func resolveHostIP() (err error) { return } + conn, err := net.Dial("udp", "1.1.1.1:80") + if err != nil { + return + } + defer conn.Close() + System.IPAddress = conn.LocalAddr().(*net.UDPAddr).IP.String() + for _, netInterfaceAddress := range netInterfaceAddresses { networkIP, ok := netInterfaceAddress.(*net.IPNet) @@ -305,13 +312,7 @@ func resolveHostIP() (err error) { var ip = networkIP.IP.String() if networkIP.IP.To4() != nil { - System.IPAddressesV4 = append(System.IPAddressesV4, ip) - - if !networkIP.IP.IsLoopback() && ip[0:7] != "169.254" { - System.IPAddress = ip - } - } else { System.IPAddressesV6 = append(System.IPAddressesV6, ip) }