如何获取客户端计算机主机名。 [英] How to get client machine host name.

查看:201
本文介绍了如何获取客户端计算机主机名。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在Windows 7 64位机器上使用过VS2010。我可以在32位机器上获得主机名并且工作正常。但是当我使用64位机器时,我得到了没有这样的主机已知的错误。

我尝试了所有这3个ServerVariables但仍然有错误。

Hello all,

I have used VS2010 on windows 7 64bit machine. I can get host name on 32bit machine and working fine. But I got error as "No such Host is known" when using 64bit machine.
I was tryed all these 3 ServerVariables but still i got error.

Request.ServerVariables["REMOTE_ADDR"]
Request.ServerVariables["REMOTE_HOST"]
Request.ServerVariables["REMOTE_USER"]



我的代码是:


My code is:

string hName = "";
System.Net.IPHostEntry host = new System.Net.IPHostEntry();
host = System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]);

if (host.HostName.Contains("."))
{
string[] sSplit = host.HostName.Split('.');
hName = sSplit[0].ToString();
}
else
{
hName = host.HostName.ToString();
}

推荐答案

它与机器的位数无关。它与远程机器是否在服务器可访问的DNS中注册有关。显然,您的64位计算机不是。
It has nothing to do with the bitness of the machine. It has everything to do with whether the remote machine is registered in a DNS accessible by the server or not. Apparently, your 64-bit machine is not.


Shrotest Way to get Client PCName

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


这篇关于如何获取客户端计算机主机名。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆