1

I've managed to get clients' ip addresses from my server using codes below

OperationContext context = OperationContext.Current;
MessageProperties prop = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ipaddress = endpoint.Address;

However, if clients are under the same network, all the ip addresses are public ip address of the network.

Is there a way to get local ip addresses of each client if they are under the same AP? or just simply, is there a easier way to distinguish client from one another?

SeungHun Cho
  • 51
  • 1
  • 4

3 Answers3

0

try this

HttpRequest currentRequest = HttpContext.Current.Request;
string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (ipAddress == null || ipAddress.ToLower() == "unknown")
    ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"];

return ipAddress;
John Saunders
  • 160,644
  • 26
  • 247
  • 397
0

Because of network address translation it is not always possible to identify clients by unique client addresses see How to get a user's client IP address in ASP.NET?

Community
  • 1
  • 1
Mike Beeler
  • 4,081
  • 2
  • 29
  • 44
0

You can try webrtc's in built feature to connect to STUN server https://diafygi.github.io/webrtc-ips/

Neil
  • 5,919
  • 15
  • 58
  • 85