get client IP details

Santosh0683
Posted by Santosh0683 under ASP.NET category on | Points: 40 | Views : 4231
here this code describes how to get client IP detail using asp.net c#
string hostIPAdd = null;
string hostName = null;
string clientIP = null;
string clientGateWay = null;
string strDNS = null;
string strHostName = System.Net.Dns.GetHostName();

hostIPAdd = this.Page.Request.ServerVariables["REMOTE_ADDR"].ToString();
hostName = HttpContext.Current.Request.UserHostName;
clientIP = System.Net.Dns.GetHostByName(strHostName).AddressList.GetValue(0).ToString();
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties adaProperties = adapter.GetIPProperties();
GatewayIPAddressInformationCollection add = adaProperties.GatewayAddresses;
if (add.Count > 0)
{
foreach (GatewayIPAddressInformation address in add)
{
clientGateWay += address.Address.ToString();
}
}
IPAddressCollection cip = adapter.GetIPProperties().DnsAddresses;
foreach (System.Net.IPAddress ip in ip)
{
strDNS = cip.ToString();
}
}

Comments or Responses

Posted by: Chvrsri on: 10/27/2010 Level:Silver | Status: [Member] [Moderator] [MVP] | Points: 10
If i want to get the Client IP address Country ??? how could we get that functionality ...
Posted by: Recursion on: 8/12/2012 Level:Starter | Status: [Member] | Points: 10
Hi visit http://www.ip-details.com/ here they provide code which help to find the location ( country ,network ,longitude ,latitude) once you entered the ip address there in search box.Using this you can get the location of your client.

Login to post response