0
votes

I was wondering if it is possible for an HTTP request to hold client's ipv4 and ipv6 addresses at the same time?

I am writing a .NET application and are probing for client's IP address using the following methods:

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
Dns.GetHostAddresses(Dns.GetHostName())

I assume an HTTP request is always made to a single address, either IPV4 or IPV6, cannot be both correct? Even if it's called by FQDN?

Is it even theoretically possible to obtain client's ipv4 and ipv6 address at the same time during a single http call?

1

1 Answers

3
votes

It is not possible to obtain multiple addresses from the client in a single HTTP request. There are several complications:

  • as you already suspected the HTTP connection uses one protocol at a time
  • it's very common for a client to have multiple IPv6 addresses, which change over time
  • the client might not have multiple addresses at all, and be IPv4-only or IPv6-only
  • using addresses as identification is tricky: ISP use NAT44 and NAT64 to save address space, IPv6 addresses often change over time (at least within the same prefix, and sometimes the prefix changes as well)

If you want to get a best-estimate then you could for example load two images on your page: one hosted on an IPv4-only hostname and one on an IPv6-only hostname. Include a unique identifier in the URL and you might be able to correlate IPv4 and IPv6 addresses for the majority of your users. But it will take multiple requests and it won't be perfect, so it's technically not an answer to your question...