在Web应用程序中获取客户端计算机名 [英] Get Client Computer Name in web application
问题描述
我正在尝试使用C#获取客户端计算机名称,但不会获得PC名称代码如下:
Hi ,
I am trying to get client computer name using C# many way but not get pc name code is below:
public ActionResult GetCleintPCName(string sid)
{
string PC1 = System.Net.Dns.GetHostEntry(Request.ServerVariables["REMOTE_ADDR"]).HostName.ToString();
string PC2 = System.Environment.MachineName;
string pcname = PC1 + " ,1: " + PC2;
string computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["REMOTE_HOST"]).HostName.ToString();
string IP = Request.UserHostName;
IPAddress myIP = IPAddress.Parse(IP);
IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
List<string> compName = GetIPHost.HostName.ToString().Split('.').ToList();
string comname= compName.First();
pcname = pcname + " 2:" + computer_name + " 3:" + comname;
return Json(new { pcName = pcname }, JsonRequestBehavior.AllowGet);
}
它没有本地主机但不在服务器上运行。
它返回服务器名称。我也尝试了java脚本和Jquery但没有得到预期的结果。
我正在研究互联网web应用程序。我想得到个人电脑名称并且基于个人电脑我得到了附件打印机如标签打印机和HP打印机,然后给出打印命令。对于打印,我使用的是neodynomic web client dll。
如何在不同的网络中获取客户端机器的MAC地址?
请给我任何链接或建议。
It working no localhost but not on server.
It returns server name.I also tried java script and Jquery but not get expected result.
I am working on internet web application.I want to get pc name and based on pc i get attached printer like label printer and hp printer and then give print command. For printing i am using neodynomic web client dll.
How can i Get MAC address of client machine in different network?
Please give me any link or suggestion.
推荐答案
没有办法确定名字 - 这取决于服务器和客户端之间各种DNS服务器的能力。
HttpRequest.UserHostName [ ^ ]应该为您提供该名称,但在大多数情况下,它会提供IP地址...
There is no way to get name for sure - it depends on the ability of the various DNS servers between your server and the client.
HttpRequest.UserHostName[^] should give you that name, but in most cases it gives IP address...
使用此命令获取客户端计算机名称
Use this to get client Machine Name
HttpRequest request = base.Request;
// Get UserHostAddress property.
string address = Request.ServerVariables["REMOTE_USER"];
这篇关于在Web应用程序中获取客户端计算机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!