Skip to content

Commit 963142d

Browse files
committed
fix pop detection
1 parent d608b9b commit 963142d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

cmd/lens/ping.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import (
1414
)
1515

1616
func ICMPPing(target string, interval float64) {
17+
if PoP == "" {
18+
log.Error().Msg("PoP is empty, skipping ICMP ping")
19+
return
20+
}
21+
1722
ctx, cancel := context.WithTimeout(context.Background(), sessionDuration)
1823
defer cancel()
1924

@@ -116,6 +121,11 @@ func ICMPPing(target string, interval float64) {
116121
}
117122

118123
func IRTTPing() {
124+
if PoP == "" {
125+
log.Error().Msg("PoP is empty, skipping IRTT ping")
126+
return
127+
}
128+
119129
ctx, cancel := context.WithTimeout(context.Background(), sessionDuration+time.Minute*10)
120130

121131
today := checkDirectory()
@@ -127,7 +137,7 @@ func IRTTPing() {
127137
defer cancel()
128138

129139
var local string
130-
if IPVersion == 6 {
140+
if IPVersion == 6 && len(externalIPv6) > 0 {
131141
local = fmt.Sprintf("--local=[%s]", externalIPv6)
132142
} else {
133143
local = fmt.Sprintf("--local=%s", IRTTLocalIP)

cmd/lens/util.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ func getExternalIP(version int) string {
143143
log.Error().Err(err).Msgf("get external IP%d addresses failed: %s", version, string(output))
144144
return ""
145145
}
146-
return strings.Trim(string(output), "\n")
146+
ip := strings.Trim(string(output), "\n")
147+
if net.ParseIP(ip) == nil {
148+
log.Error().Msgf("get external IP%d addresses failed: invalid IP %s", version, ip)
149+
return ""
150+
}
151+
return ip
147152
}
148153

149154
func getStarlinkPoP(ip string) string {
@@ -243,6 +248,7 @@ func getStarlinkIPv6ActiveGateway() string {
243248
func getGateway() string {
244249
gatewayIP := ""
245250
externalIP := ""
251+
PoP = ""
246252

247253
if ManualSpecifiedGateway != "" {
248254
if net.ParseIP(ManualSpecifiedGateway).To4() != nil {
@@ -326,8 +332,6 @@ func getGateway() string {
326332

327333
if externalIP != "" {
328334
PoP = getStarlinkPoP(externalIP)
329-
} else {
330-
PoP = ""
331335
}
332336
StarlinkGateway = gatewayIP
333337

0 commit comments

Comments
 (0)