Tuesday, February 18, 2025
HomeGolangWhich bundle to make use of to get the true IP of...

Which bundle to make use of to get the true IP of the shopper? – Getting Assist


I’m undecided, I need to determine the request of a shopper, and what higher than utilizing the IP, however my choices I don’t know which one is extra dependable:

Native choice with the web bundle:

func PrintIP(l web.Listener) {
	fmt.Println(fmt.Sprintf("<%s> %s", l.Addr().Community(), l.Addr().String()))
}

Exterior choice with github.com/tomasen/realip bundle:

func PrintIP(r *http.Request) {
	fmt.Println(realip.FromRequest(r))
}

Does web.Listener hold the true IP of the shopper? As a result of in that case I want to make use of that choice but when not, then I assume it’s best to make use of realip.FromRequest or is there a greater suggestion?.

web.Listener works for getting the IP for arbitrary connections, whereas realip.FromRequest works for HTTP, however will very possible provide the IP of the true shopper, not the IP of the proxy it makes use of. Although this IP can in principle be from a personal community, additionally not all proxies set the headers that will inform you the unique IP.

On the finish it will depend on your usecase.



1 Like

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments