How to get real client IP from net.Conn?

Hello. I was playing with conn.RemoteAddr() of connected client and noticed that clients address is the same as my PC but with different port. Google shows solution for net/http package but I don’t use http. So I was wandering how to get real client’s IP address?

1 Like

Hey there! You are probably getting the localhost IP, aka, which is always your computers local IP. conn.RemoteAddr() will always return that IP locally, but if you test across the network from somewhere else you will see other results.

You probably figured this out by now, but it’s a easy mistake to make and nothing to be embarrased about :slight_smile: Just thought I’d write you an answer so that if someone has the same problem in the future they know why.

Hi Kristoffer :slight_smile: You are right. As soon as I posted this topic I had an enlightenment to check to connect from external IP and I sow what I was expecting :slight_smile: Thanks for the help :slight_smile:

1 Like

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