HOW TO GET CLIENT MACHINE NAME AND SERVER NAME

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
C#
 3735  View(s)
Ratings:
Rate this:
How to get Client Machine Name And Server Name
  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to get Client Machine Name And Server Name

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!