How to get Internet protocol address using 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 is very simple and very easier.
This is the way to track the users Internet protocol address.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.
Here am giving two methods to find the Internet protocol adress.
using System.Net;//Add the Namespace
//Get Visitor IP address method
public string GetVisitorIpAddress()
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 "Visitor 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();
you will get their ip address.