tags:

views:

1071

answers:

3

In my ASP.NET application, I'm saying something like this to get the client IP address:

string ipAddress = HttpContext.Current.Request.UserHostAddress;

This is the normal, straightforward way that I've always used, and it's always seemed to work. Everybody knows that the above statement is just a wrapper for the REMOTE_ADDR server variable.

Simple enough, right? Well, in the last few days I've been noticing that on my local dev machine, it's returning this as the value:

"fe80::dde4:def3:7f1b:a582%10"

I have no earthly idea why. I'm running Vista x64 and running my app with IIS7. I do have IPv4 and IPv6 enabled, but that usually returns something like:

"1::"

I have no idea why this is happening. Rebooting solves nothing.

EDIT:

I'm using Chrome when this happens.

+7  A: 

It looks like it's returning IPv6.

::1 is the loopback address for IPv6, which is simply the reversed byte order of 1::.

I should also note that fe80::/10 addresses in IPv6 are Autoconfiguration IP addresses (in IPv4, these are 169.254.0.0/16). If for example you are on a private LAN and cannot access a DHCP server, Windows will automatically assign your ethernet adapter an autoconfiguration IP address.

Just FYI, You should generally assign a private IP address to adapters that are not able to reach a DHCP server.

John Rasch
Hmm, you're right. I've never seen what IP6 looks like before. I'll look into this. Upvote for now for the info.
+4  A: 

Are you using FireFox when you see this issue? That by default will use IPv6 when available. I'd recommend turning that off:

  • Navigate to "about:config"
  • Find the "network.dns.disableIPv6" entry
  • Set it to true

This will also speed up local development and debugging, as FF hangs sometimes for no apparent reason when IPv6 is enabled.

The other option I'd recommend is to just disable IPv6. It's not useful right now unless you're running IPv6 end-to-end, which no end user ISP's are. Just open connection properties on your connection and untick the "Internet Protocol Version 6 (TCP/IPv6)" box.

Chris Hynes
I'm using Chrome. I'll see what happens with your suggestions.
I have the same configuration as PaulW, and testing with FF with IPv6 entry enabled, I get the IPv4 address in both properties.
jro
Actually, I already had that set to true. I was using Chrome anyway, but Firefox was returning IPv4.
A: 

This article on 4guysfromrolla has the solution for this http://aspnet.4guysfromrolla.com/articles/071807-1.aspx