How to get IP address of a client machine in csharpIntroduction
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.........