Client IP Address



Can I get the IP address of a client connecting to my service?

No. Sorry. In most cases this information is not available. Exposing such functionality is left to the transport to be done in an implementation-specific manner. The most popular transports we supply out of the box do not offer this. You can ask the client to supply that information as part of its identity, although you need a way of making sure that the client isn't lying before taking action based on the IP address. However, it is possible under some circumstances for the client to lie about its address even when you can directly query the socket.

Comments (9)

  1. Michael says:

    Yes, but it’d be so nice if MS would let us know how we could get it for, say, TCP and HTTP bindings.

    For example, almost the entire world of VoIP communication relies only on IP authentication. Regardless if it’s not secure, it’s a business requirement and we’re stuck with a problem when we can’t track IPs. For now, we have to run those services in IIS and turn on the ASP.NET compatible mode to access HttpContext, but of course that only helps where we’re using HTTP and IIS…

  2. Jeff says:

    From a security standpoint this is crazy that this information isn’t available. I am amazed that this is suppose to be the new way of doing communication and it doesn’t provide of way of getting something so basic.

    I can think of a good reason not to depend on what the client says… Network Address Translation.

  3. MichaelGiagnocavo says:

    Even with NAT, at least you have the NAT’d IP, and _most_ companies are operating under the premise that their own LAN is correctly secured and routed.

    That said, billions of dollars flow based purely on IP authentication (over UDP none-the-less).

    Having the client send their IP is pointless :.

  4. Scott Seely says:

    It should be noted that transports that DO know about this information will deposit Information level traces into any tracing that you are doing with respect to the connection.

  5. Michael says:

    Right the transports must know, so how can we get it (via reflection or something)?

  6. You can of course pull the data out through a few uses of reflection.  It it worthwhile to do so?  Your program will be very brittle and likely to break with the slightest of changes as it’s intimately depending on internal implementation details.

  7. LeoD says:

    I am very disappointed with WCF.

    This is _basic stuff_. We should be able to easily have this IP address info.

  8. David says:

    Nicholas,

    Can you explain WHY the ip address is not made available in the transport? I have never heard of a server logging mechanism that didn’t include the ip address as a basic piece of information. Even if it cannot be completely relied upon, its better to have the information than not have it.

  9. MichaelGiagnocavo says:

    I’d be more than happy to pull it out via reflection — where should I look? It’ll break with the next framework: I can handle that.

Skip to main content