vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Monday, November 5, 2012

How to get the current system IP address in asp.net


Hi
Really am very proud to write the article with DotNetCode, they way to reach this article to help many people to save their time.
Article is about to client IP address from the machine, using C# code.i knew many people to search this code to find the system IP address.
Normally when we try to get the system IP its always return the server IP address instead of return the current  system IP address, here I solve the problem by the below code to get the current system IP address.
Code:

HttpRequest IPRrequest = HttpContext.Current.Request;
            string IPaddr= IPRrequest.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (IPaddr== null || IPaddr.ToLower() == "unknown")
                IPaddr= IPRrequest.ServerVariables["REMOTE_ADDR"];

            return IPaddr;


 Above code return the current system ip address eventhough the system connected on the network.
I hope you like this article..share this article with your friends.

0 comments:

Post a Comment