Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IP of the client?

Tags:

servicestack

I've wrote a self-hosted servicestack server and a client, both desktop applications. In my very basic PING test service I'm trying to retrieve the IP of the client. Server is on 192.168.0.87:82, client I tried on the same computer and on another computer, but RemoteIp and UserHostAddress always return 192.168.0.87:82. XRealIp is null. I also tried base.Request.RemoteIp, but still is 192.168.0.87:82.

What am I doing wrong?

public RespPing Any(ReqPing request)
    {
        string IP = base.RequestContext.Get<IHttpRequest>().RemoteIp;
        string MAC = request.iTransactionInfo.MAC;

        Log(MAC,IP, base.RequestContext.Get<IHttpRequest>().RemoteIp + base.RequestContext.Get<IHttpRequest>().XRealIp + base.RequestContext.Get<IHttpRequest>().UserHostAddress);

        RespPing response = new RespPing { Result = "PONG" };

        return response;
    }

Thanks!

like image 396
Mattia Durli Avatar asked Dec 03 '25 16:12

Mattia Durli


1 Answers

Made it with:

HttpListenerRequest iHttpListenerRequest = (HttpListenerRequest)base.RequestContext.Get<IHttpRequest>().OriginalRequest;

string IP = iHttpListenerRequest.RemoteEndPoint.ToString().Split(':')[0]; 

Request.RemoteIP kept giving me the server address.

like image 100
Mattia Durli Avatar answered Dec 07 '25 02:12

Mattia Durli