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;
}

1 comment:

Quanda said...

Good words.