Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPv4 remote address in WCF

Tags:

c#

tcp

wcf

Related to How to get the IP address of a WCF remote endpoint?

I am using this code to retrieve the remote IP address when a workflow method is invoked:

private static string GetRemoteIP()
{
  var oc = OperationContext.Current;
  var mp = oc.IncomingMessageProperties;
  var remp = mp[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

  return remp == null ? "(unknown)" : remp.Address;
}

However, the address I get back is "::1". I don't want the IPv6 address, I want the IPv4 one (127.0.0.1) - any way of forcing this?

like image 243
Marcel Popescu Avatar asked Jan 08 '10 16:01

Marcel Popescu


People also ask

How do I find the IP address of HttpServletRequest?

In Java, you can use HttpServletRequest. getRemoteAddr() to get the client's IP address that's accessing your Java web application.

Which method returns the client IP address from Servletrequest?

getRemoteAddr. Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR .


1 Answers

No, I don't think so. You basically just read out a property set by the client at the time of the call. Your only option would be to instruct the client (through some config) to use IPv4 instead of IPv6 at all times (i.e. turn off IPv6 all together).

I'm not aware of any WCF setting to enforce that - you'd have to dig into the network stack and see if there's any way to make it use IPv4 addresses instead of IPv6.

like image 57
marc_s Avatar answered Oct 01 '22 10:10

marc_s