Home > DeveloperSection > Forums > How to get Client Machine Name And Server Name
Samuel Fernandes
Samuel Fernandes

Total Post:154

Points:1082
Posted on    September-22-2014 4:46 AM

 C# .NET  ASP.NET MVC  C# 
Ratings:


 1 Reply(s)
 2402  View(s)
Rate this:
How to get Client Machine Name And Server Name


Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Supported
Posted on    September-22-2014 4:48 AM

Hi  Samuel
Here Html code

<h1>Client Machine Name:<span> @ViewBag.PcName</span></h1>

<h1>Server Machine Name: <span>@ViewBag.HostPCName</span></h1><p></p>

Here is C# Code:

public ActionResult Index()
        {
            string PCName = Dns.GetHostEntry(Request.ServerVariables["REMOTE_ADDR"]).HostName;
            string HostPCName = Dns.GetHostName();
            ViewBag.PcName = PCName;
            ViewBag.HostPCName = HostPCName;

            string strDNS = Dns.GetHostName();
            string aa = System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString().Trim();
            string bb = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(5).ToString().Trim();

            //Retrieving Server IPAddress                    
            string strHostName = System.Net.Dns.GetHostName();
            string strHostIPAddress = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString();

            string a = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;
            //string b = ServerVariables["REMOTE_ADDR"];
            string c = Request.UserHostAddress;
            string d = Server.HtmlEncode(Request.UserHostName);

            //Get The User Ip Address
            string ipAddress = "117.214.129.9";
            string str = Request.Form["hdn"];
            string MyUserName = Environment.UserName;
            string MyDomainName = Environment.UserDomainName;
            string MyComputerName = System.Net.Dns.GetHostName();
            string MyIPAddress = System.Net.Dns.GetHostEntry(MyComputerName).AddressList[0].ToString();

            //Retrieving Client Machine details
            System.Net.IPAddress[] strClientIPAddress = System.Net.Dns.GetHostAddresses(Environment.MachineName);
            string strClientMachineName = Environment.MachineName.ToString().Trim();
            string strClientUserName = Environment.UserName.ToString().Trim();
            string strClientDomainName = Environment.UserDomainName.ToString().Trim();
            string strClientOSVersion = Environment.OSVersion.ToString().Trim();

            string[] computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName.Split(new Char[] { '.' });
            computer_name[0].ToString();

            //string getUserHostAddress = HttpContext.Current.Request.UserHostAddress;
            //string getUserHostName = HttpContext.Current.Request.UserHostName;
            return View();
        }

Don't want to miss updates? Please click the below button!

Follow MindStick