I use Request.UserHostAddress
, can only get IPv4 address, how to get IPv6 address of a visitor?
Asked
Active
Viewed 6,646 times
9

Eric Yin
- 8,737
- 19
- 77
- 118
-
3A visitor's going to have EITHER a v4 OR a v6 address. They won't be coming in with both. – Marc B Feb 01 '12 at 22:02
-
1Is the user accessing the web site over IPv6 in the first place? See http://stackoverflow.com/questions/9061470/get-user-ip-in-c-sharp. – GSerg Feb 01 '12 at 22:03
-
1You can always convert an IPv4 address manually to an IPv6: http://www.fnode.com/2009/11/convert-ipv4-into-ipv6/ – Max Feb 01 '12 at 22:06
2 Answers
13
I assume you're talking about HttpRequest.UserHostAddress
. It will always return the address that was used to connect to you. If the request was made over IPv6, it will return their IPv6 address; if the request was made over IPv4, it will return their IPv4 address.
You should start by investigating why the request is being made over IPv4. And the folks at http://serverfault.com will probably be of more help on that.

sblom
- 26,911
- 4
- 71
- 95
6
An IPv4 address is translated to an IPv6 address by placing the 4 octets of the IPv4 address into the rightmost 4 octets of the IPv6 address.
After inserting the 4 octets of the IPv4 address into the rightmost 4 octets of the IPv6 address, the remaining left-most octets would be 0 in value.

Dmitry Savy
- 1,067
- 8
- 22