You can only find one client IP address per request. If you want to display both address to the client, you need two requests. This can be done using javascript or an iframe.
To do it properly, you are going to need three domains.
- A primary domain with dual stack
- An IPv4-only domain.
- An IPv6-only domain.
When the user access the primary domain their browser will decide whether to use IPv4 or IPv6. If an up to date browser is being used it will within a few milliseconds figure out which protocol is more efficient on this particular connection.
When you process the request you will find one of the two addresses. You can then include a link to a URL which will find an address of the other family. Be aware that this will fail if the user has access to only one of the two address families.
Be careful about proxies. If you trust X-Forwarded-For
from an untrusted proxy, the user can trivially spoof any IP address.
Also notice that in case of a legitimate proxy, you will have no control over the address family used between client and proxy. It is entirely possible that they are using a proxy because the client machine only has an IP address of one of the two families, and in that case you are not going to find a client address in the other family, because it simply does not exist. You can still use the method described above to find both addresses of the proxy - assuming that the proxy actually allows the user to access both IPv4 and IPv6.
In more advanced configurations it is even possible that the user use a proxy for some requests and not for other requests. So you need to be prepared to handle a situation where only one of the two requests used a proxy.
In most cases the best approach is to simply ignore all that proxy information and only use the IP address you actually got the request from.