@@ -121,11 +121,26 @@ func GetWslStatus(instName string) (string, error) {
121
121
// Expected output (whitespace preserved, [] for optional):
122
122
// PS > wsl -d <distroName> bash -c hostname -I | cut -d' ' -f1
123
123
// 168.1.1.1 [10.0.0.1]
124
+ // But busybox hostname does not implement --all-ip-addresses:
125
+ // hostname: unrecognized option: I
124
126
func GetSSHAddress (instName string ) (string , error ) {
125
127
distroName := "lima-" + instName
128
+ // Ubuntu
126
129
cmd := exec .Command ("wsl.exe" , "-d" , distroName , "bash" , "-c" , `hostname -I | cut -d ' ' -f1` )
127
130
out , err := cmd .CombinedOutput ()
128
- if err != nil {
131
+ if err == nil {
132
+ return strings .TrimSpace (string (out )), nil
133
+ }
134
+ // Alpine
135
+ cmd = exec .Command ("wsl.exe" , "-d" , distroName , "sh" , "-c" , `ip route get 1 | awk '{gsub("^.*src ",""); print $1; exit}'` )
136
+ out , err = cmd .CombinedOutput ()
137
+ if err == nil {
138
+ return strings .TrimSpace (string (out )), nil
139
+ }
140
+ // fallback
141
+ cmd = exec .Command ("wsl.exe" , "-d" , distroName , "hostname" , "-i" )
142
+ out , err = cmd .CombinedOutput ()
143
+ if err != nil || strings .HasPrefix (string (out ), "127." ) {
129
144
return "" , fmt .Errorf ("failed to get hostname for instance %q, err: %w (out=%q)" , instName , err , string (out ))
130
145
}
131
146
0 commit comments