kos/entry/http/context_test.go

29 lines
463 B
Go

package http
import (
"net"
"strings"
"testing"
)
func TestContext_RealIp(t *testing.T) {
var (
pos int
s string
)
ipaddr := "192.168.6.76, 192.168.6.76, 116.24.65.173,192.168.6.76"
for {
if pos = strings.IndexByte(ipaddr, ','); pos > -1 {
s = strings.TrimSpace(ipaddr[:pos])
if netip := net.ParseIP(s); netip != nil && !netip.IsPrivate() {
t.Log(s)
break
}
ipaddr = ipaddr[pos+1:]
} else {
break
}
}
t.Log(ipaddr)
}