1

For obtaining client IP in WCF i use the following method:

public static byte[] GetUserIP(OperationContext context)
        {
            var messageProperties = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpointProperty =
                messageProperties[RemoteEndpointMessageProperty.Name]
                as RemoteEndpointMessageProperty;

            return GetIPFromString(endpointProperty.Address);
        }

My machine has some local IPv4 and this method was working until yesterday.. May be our network admins changed something; i dont know, but now the endpointProperty.Address is returning "::1" and not "xxx.xxx.xxx.xxx". Can someone explain what can cause such thing?

0x49D1
  • 8,505
  • 11
  • 76
  • 127

1 Answers1

3

This is because your machine is now using IPv6 loopback instead of IPv4.

It will also affect intranet IP addresses as your Admins have likely enabled IPv6 across the board - so Machine A will identify itself to Machine B with it's IPv6 address.

In a public environment it's unlikely to cause a problem until the entire interweb moves to IPv6.

Either way, you should ensure that you use the methods in IPAddress to parse the endpoint's IP rather than hand-cranking your own.

I also got caught out by a similar problem when I set up a database column that would be used to track IP addresses as varchar(15); worked greta until the same thing happened to us internally and all of a sudden all my request logging starting breaking on internal requests!

Andras Zoltan
  • 41,961
  • 13
  • 104
  • 160
  • Thank you for the answer..I though about this, but ::1 seemed strange to me..Is it kind of 127.0.0.1 for IPv6?! – 0x49D1 Mar 15 '11 at 12:32
  • 1
    yup ::1 is indeed ipv6 loopback. there are also other well-known IPv6 addresses (but they don't exactly roll off the tongue). – Andras Zoltan Mar 15 '11 at 12:33
  • I had a similar requirement and using the above line of code gives me IPV6, instead I am looking for mac address of the client to be able to identity clients who are not on same network (like VPN). Below is the link of my query posted anything on the same is highly appreciated as I am stuck in critical deadline: https://stackoverflow.com/questions/66143909/get-clients-mac-address-at-server-side-in-wcf-service-c-sharp#comment116940387_66143993 – NP_22 Feb 10 '21 at 20:32