2

I have searched, but cannot seem to find an answer to this simple question:

How do I force symfony to give me the ipv4 version of user's ip, or am I missing something ?

Can I get both ipv4 and ipv6 ?

Thanks

Edit: My question is different, because I am not trying to get any ip, I know of the function getClientIP ( that's why it is in the title ), I want the function to return an ipv4 and ipv6 version of ip. ( or any function, any way to get both, ipv4 and ipv6 )

Edit2: that is how I get ip right now:

public function getUserIp()
{
    return $this->request->getClientIp();
}

and it returns ipv6 exclusively. ( this function is ran from inside of my own UserManager, that checks and updates the current user on every call, by plugging an event to the controller enter part symfony pipeline )

user1494173
  • 169
  • 1
  • 4
  • 11

1 Answers1

5

If user connected with IPv6 then there is no IPv4 address to display and vice versa. You always get only one version of IP.

imran
  • 155
  • 1
  • 9
  • But user has both ipv6 and ipv4, correct ? What determines which ip does the user connect with ? The server ? – user1494173 Apr 01 '15 at 16:11
  • 2
    No, the IP address that the server knows about is the one that the client connected from. Generally, the end points of a socket are on one port of one IP address, and that's all that the other end knows about. To get both the IP addresses from the Client, the client would have to explicitly send it to you. – Daniel Apr 02 '15 at 01:00
  • Your explanation makes sense, and it's probably true, but I had a situation in which, somehow, I made symfony get the ipv4 instead of ipv6, obviously, just one of them ( since, just like You said, it is impossible to get both ), but I do not know what made symfony get ipv4. Is there a way to turn on/off ipv6 support per request ? – user1494173 Apr 03 '15 at 12:26
  • 1
    Sorry, for the confusion, obviously, You were right, the problem was actually caused by my boss' mistake, or maybe just clumsiness, who knows, he turned "Only IPv6" option in Cloudflare ... my bad. – user1494173 Oct 01 '15 at 18:40