I have found that in various forum newbie are very frequently asked this type of question how to get client IP or get mac address or country. So that I would like to share this for that user. Though its very simple but helpful.
To get the client IP you can use the following function
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
Tip:2:To avoid Proxy IP:
To get the IP address of the machine and not the proxy use the following code
This will returns the client ip in string format.
REMOTE_ADDR does not always provide the users IP but rather the ISPs’ IP address so first test HTTP_X_FORWARDED_FOR as this one is the real user IP.
Another important note to this the HTTP_X_FORWARDED_FOR may contain an array of IP, this can happen if you connect through a proxy.What also happens when this happens is that the REMOTE_ADDR may contain the proxy IP. To avoid this problem you can parse the HTTP_X_FORWARDED_FOR for first entery IP.
string ipRange = ip.Split(‘,’);
string trueIP = ipRange.Trim();
Hope that it may helpful for the newbie.Please inform me if anything wrong in this article.