12345678910111213141516171819202122232425262728 |
- 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)
- }
|