User Id :    Password :      New Member   Forgot Password  
 
How to get IP address of a client machine in csharp
Description In my recent project I was told keep track of the IP address of all the visitors. Here I will show you how to get IP address of the client machine in csharp in asp.net.   No. of Views     8329
  Rating     4
Author Najmul Hoda   Posted On     18 Oct 2010
Tags ASP.NET,C#    

Sample Code   Download Code

Introduction

In my recent project I was told to keep  track of the IP address of all the visitors. Here I will show you how to get IP address of the client machine in csharp in asp.net.

There are many ways you can get the IP address of a client machine.

1. 

 string strClientIp=Request.UserHostAddress();

2. 

string strDNS = Dns.GetHostName();
string strClientIP = HttpWorkerRequest.GetRemoteAddress().ToString();
 

3. If you are calling from web service use code below

string strClientIP = Context.Request.ServerVariables ["REMOTE_ADDR"] 

4. 

string host = Dns.GetHostName();
IPHostEntry ip = Dns.GetHostEntry(host);
string strClientIP = ip.AddressList[0].ToString());

Enjoy coding.........

About Author

About Author He is a team lead, having 8+ years of experience. He loves writing technical article for .Net developers. Najmul Hoda
No Photo
 
Country United States
Company BirlaSoft
Home Page http://www.magixchat.com

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

 
 
Posted By Nilanjan on 03 Aug 2011 at 12:52 AM
 
hi This code is useless
 
 
   
Write your comment here.
Comment
Verification Code