Showing posts with label Client IP address. Show all posts
Showing posts with label Client IP address. Show all posts

Tuesday, August 25, 2009

ASP.NET Client IP address, Client Host Name, visitor's browser type etc.

ASP.NET Client IP address, Client Host Name, visitor's browser type etc.
This example demonstrates how to find out the visitor's browser type, IP address, and more:

<html>
<body>
<p>
<b>You are browsing this site with:</b>
<%Response.Write(Request.ServerVariables("http_user_agent"))%>
</p>
<p>
<b>Your IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</p>
<p>
<b>The DNS lookup of the IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_host"))%>
</p>
<p>
<b>The method used to call the page:</b>
<%Response.Write(Request.ServerVariables("request_method"))%>
</p>
<p>
<b>The server's domain name:</b>
<%Response.Write(Request.ServerVariables("server_name"))%>
</p>
<p>
<b>The server's port:</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>The server's software:</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
</body>
</html>

Friday, July 11, 2008

Getting Client Host name using Java Script/C#

Getting Client Host name using Java Script

function GetComputerName()
{
try
{
var WshNetwork = new ActiveXObject("WScript.Network");
var hostname = WshNetwork.ComputerName.toLowerCase(); document.getElementById('HdnMachineId').value = hostname;
}
catch(err)
{ }
}

Getting Client Host name using C#

private string getClientHostName()
{
// Get HostName of client computer
string hostname = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"].ToString().ToLower();
try
{
System.Net.IPHostEntry host = System.Net.Dns.GetHostByAddress(hostname);
hostname = host.HostName;
}
catch(Exception exp)
{

}
return hostname;
}

Monday, June 09, 2008

Getting Geographic Location(country) of internet user ASP.NET C#

Here is a FREE web service that will give you Country information from IP address.
http://www.webservicex.net/WS/WSDetails.aspx?WSID=64&CATID=12

But if you want to pay and get more featured service, then you may check here
http://www.ip2country.net/ip2country/lookup.html
This website does not sell Web Service, rather they sell lookup DataBase. You will need to purchase a database from them and then use your ASP.NET look up query to get county information.

Getting Client IP address using ASP.NET C#

You can use the following three ways to get the client IP address using C#

string test = Request.UserHostAddress.ToString();
string test2 = Request.ServerVariables["REMOTE_ADDR"].ToString();
string test3 = Context.Request.UserHostAddress.ToString();

All are returning the same values...

Some times client can mask their IP behind a router/nat and it's spoofable.