How to get a client's ip address with ASP.NET :
Internet protocol is a communication between the nodes. Internet protocol, which is used to track a system host and used address the location. If we need to identify the user who are all accessing our website and store the Internet protocol address in our database.
Fetch a client's Internet protocol address as soon as he access our web site in asp.net. Some of them may use a proxy Internet protocol address. But we can get their Internet protocol address with this simple code.
Code:
Share this to your friends. Thanks!
Internet protocol is a communication between the nodes. Internet protocol, which is used to track a system host and used address the location. If we need to identify the user who are all accessing our website and store the Internet protocol address in our database.
Fetch a client's Internet protocol address as soon as he access our web site in asp.net. Some of them may use a proxy Internet protocol address. But we can get their Internet protocol address with this simple code.
Code:
//Add the Namespace
using System.Net;
using System.Net;
//Get Visitor IP address method public string GetVisitorIpAddress() { string stringIpAddress; stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (stringIpAddress == null) //may be the HTTP_X_FORWARDED_FOR is null { stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];//we can use REMOTE_ADDR } return "Your ip is "+stringIpAddress; }
//Get Lan Connected IP address method public string GetLanIPAddress() { //Get the Host Name string stringHostName = Dns.GetHostName(); //Get The Ip Host Entry IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName); //Get The Ip Address From The Ip Host Entry Address List IPAddress[] arrIpAddress = ipHostEntries.AddressList; return arrIpAddress[arrIpAddress.Length - 1].ToString(); }
//Get The Visitor Ip Address string strVisitorIpAddress = GetVisitorIpAddress(); //Get The Lan Ip Address string strLanIpAddress = GetLanIPAddress();
8 comments:
good one.. working ....
thnaks yaarr
ipHostEntries.AddressList; Gives Error like:Cannot Implicitly convert type "System.Net.IPAddress[]" to "IPAddress"
thank you , but it keep telling me that "Request.ServerVariables" is not in the current context ?!
in your get Ip lan function has output for IP provider not lan IP
giving ::1 for IPV6
It’s never too late to improve your information and your contents inspire me.
iphone backup extractor
Super!!!!!
Awesome .. very helpful!
iPhone photo recovery
Post a Comment
Share your thoughts here...