# Which package to use to get the real IP of the client?

**URL:** <https://forum.golangbridge.org/t/which-package-to-use-to-get-the-real-ip-of-the-client/37611>\
**Category:** Getting Help\
**Created:** [January 27, 2025, 11:59pm UTC](https://forum.golangbridge.org/t/which-package-to-use-to-get-the-real-ip-of-the-client/37611 "2025-01-27T23:59:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Willy](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/willy/32/11447_2.png) [@Willy](https://forum.golangbridge.org/u/Willy)\
**Post date:** [January 27, 2025, 11:59pm UTC](https://forum.golangbridge.org/t/which-package-to-use-to-get-the-real-ip-of-the-client/37611/1 "2025-01-27T23:59:27Z")

</div>

I’m undecided, I want to identify the request of a client, and what better than using the IP, but looking at my options I don’t know which one is more reliable:

Native option with the `net` package:

```auto
func PrintIP(l net.Listener) {
	fmt.Println(fmt.Sprintf("<%s> %s", l.Addr().Network(), l.Addr().String()))
}

```

External option with `github.com/tomasen/realip` package:

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

```

Does `net.Listener` keep the real IP of the client? Because if so I prefer to use that option but if not, then I guess it is best to use `realip.FromRequest` or is there a better suggestion?.

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/nobbz/32/3096_2.png) [@NobbZ](https://forum.golangbridge.org/u/NobbZ)\
**Post date:** [January 28, 2025, 5:52am UTC](https://forum.golangbridge.org/t/which-package-to-use-to-get-the-real-ip-of-the-client/37611/2 "2025-01-28T05:52:22Z")

</div>

`net.Listener` works for getting the IP for arbitrary connections, while `realip.FromRequest` works for HTTP, but will very likely give you the IP of the real client, not the IP of the proxy it uses. Though this IP can in theory be from a private network, also not all proxies set the headers that would tell you the original IP.

At the end it depends on your usecase.

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [April 28, 2025, 5:52am UTC](https://forum.golangbridge.org/t/which-package-to-use-to-get-the-real-ip-of-the-client/37611/3 "2025-04-28T05:52:46Z")

</div>

Closed on April 28, 2025, 5:52am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
