# برنامه نویسی با محصولات مایکروسافت > برنامه نویسی مبتنی بر Microsoft .Net Framework > WCF , Web Services , .Net Remoting > سوال: بدست آوردن IP کلاینت

## kiadata

با سلام خدمت دوستان و سروران عزیزم

من یک وب سرویس نوشتم که برای بالا بردن امنیتش لازمه که کاربرانی که از طریق اینترنت با هر مرورگری که وصل میشن ip شونو داشته باشم

کدهای زیادی پیدا کردم ولی همشون IP جایی که وب سرویسم اجرا می شه رو برمی گردونن چه جوری میتونم ip مرورگرهای کلاینتو بدرستی دریافت کنم با WCF Web Service لطفا راهنمائیم کنید ممنونم.

این هم نمونه کدی از کدهاییکه استفاده میکنم :


 public string YourIPK2()
          {
              OperationContext context = OperationContext.Current;
              MessageProperties messageProperties = context.IncomingMessageProperties;
              var endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;


              string clientIP = endpointProperty.Address;
              string clientIPWithPort = string.Concat(endpointProperty.Address, ":", endpointProperty.Port);
              return clientIPWithPort;
          }

----------


## m.fazlali

There doesn't appear to be a reliable way to get the client IP for a WCF  .Net you can and it's done exactly how  you've described in your question.

If your client IP is on the same network you should be able to get the  IP.  But if it's not it's important to remember how internet routing and  network address tables (NAT) work.

If your clients are not connected directly to the internet and is  accessing it via a router, it's possible that many of your clients could  be sharing the same IP address as the only visible IP address will be  the public IP assigned to the network by their internet service provider  (This is often called a none NAT address or real address).

In larger corporate networks this can be further obfuscated as they  could have multiple levels of NATs between you and your client.

If that wasn't enough, if your client is behind a load balanced proxy,  you could find that the same client doesn't always come from the same ip  address.  An IPv4 address is split into four bytes.  192.168.0.1.  192  is the class A, 168 is the class B, 0 is the class C and the 1 is the  class D part.  You may find your client's subsequent requests are coming  from multiple class D addresses.  This is also an issue you come across  when configuring load balanced web servers which require server  affinity for state management.  If you don't configure the affinity to  class C addresses (So all matching class C address go to the same  server) then you'll soon run into state management issue with corporate  users

----------


## kiadata

سلام ممنونم - لطفا امکانش بود فارسی بنویسید

----------


## kiadata

با سلام دوستان من از کد زیر هم استفاده کردم ولی باز ادرس ای پی ومپ سرور پی اچ پی رو بر می گردونه جایی که کدهای اینترفیسه پی اچ پی هست در حالیکه

من میخوام ادرس ای پی کاربرانیکه لاگین میشنو بگیرمو توی دیتابیس ذخیره کنم ممنون میشم رهنمایی کنید.


 public string myIPA()
          {


              //HttpRequest request = base.Request;
              HttpRequest request = HttpContext.Current.Request;
              string address = request.UserHostAddress;
              return address;
          }

----------

