~~~
测试了如下都不成功 得不到访问者客户的IP地址
fmt.Println(r.RemoteAddr)
fmt.Println(r.Header.get("Remote_addr"))
请问还有什么函数可以获取 客户端IP呢。
~~~
<a href="/user/polaris" title="@polaris">@polaris</a>
~~~
我直接输出的
fmt.Fprintln(w, RemoteIp)
怎么返回的是 0x72b650 而不是IP呢
~~~
#7
更多评论
```go
func RemoteIp(req *http.Request) string {
remoteAddr := req.RemoteAddr
if ip := req.Header.Get(XRealIP); ip != "" {
remoteAddr = ip
} else if ip = req.Header.Get(XForwardedFor); ip != "" {
remoteAddr = ip
} else {
remoteAddr, _, _ = net.SplitHostPort(remoteAddr)
}
if remoteAddr == "::1" {
remoteAddr = "127.0.0.1"
}
return remoteAddr
}
```
#2