-
Notifications
You must be signed in to change notification settings - Fork 0
IP Handler
poteto edited this page Nov 27, 2024
·
3 revisions
- Get from X-Forwarded-For
- Get from X-Real-Ip
- Get from RemoteAddr
- RegisterIPRanges
iph := &ipHandler{}
_, ipnet, _ := net.ParseCIDR("10.0.0.0/24")
iph.RegisterTrustIPRange(ipnet)- GetIP
ipString, _ := iph.RealIP(ctx)It requires >=0.22.0
Each time a proxy is connected, it is given behind it. For example, if x -> a -> b -> app, x, a, b are listed.
If you want to get the first request, it seems like you should get the first x, but not because the initial value can be set freely.
Therefore, the following is obtained in order from right to left, and the unregistered ip is assumed to be the request source ip.
- RegisterIPRanges
iph := &ipHandler{}
_, ipnet, _ := net.ParseCIDR("10.0.0.0/24")
iph.RegisterTrustIPRange(ipnet)- GetIP
ipString, _ := iph.GetIPFromXFFHeader(ctx)it requires >=0.16.0
From RemoteAddr
func hoge(ctx poteto.Context) {
ip, err := ctx.GetRemoteIP()
}