简体   繁体   English

如何确定Windows计算机的身份?

[英]How do I determine the identity of a Windows machine?

I have a program consisting of a server and a client processes. 我有一个包含服务器和客户端进程的程序。 Both run on Windows systems - Windows 2000 or later versions. 两者都在Windows系统-Windows 2000或更高版本上运行。 The two processes can run on the same machine or on two different machines. 这两个进程可以在同一台计算机上运行,​​也可以在两台不同的计算机上运行。

How can the client determine if it is run on the same machine as the server? 客户端如何确定它是否与服务器在同一台计算机上运行? If the server is not running the client can't work anyway and doesn't care where the server possibly is - so this case is out of the question. 如果服务器未运行,则客户端无论如何都将无法工作,也不在乎服务器可能在何处-因此,这种情况是不可能的。 I've heard that each Windows machine has an UUID - can I obtain it and use for that purpose? 我听说每台Windows机器都有一个UUID-我可以获取它并将其用于此目的吗?

Previous question about generating a unique machine id that might help. 上一个有关生成唯一机器ID的问题,该ID可能会有所帮助。 Link to previous answer which mentions MachineGUID 链接到前面提到MachineGUID的答案

It is straightforward to add an API to the server that reports its machine name. 向报告其机器名称的服务器添加API很简单。 The environment variable is COMPUTERNAME. 环境变量是COMPUTERNAME。 The client could check that, right? 客户可以检查一下,对吗?

Do you need to deal with any of these cases? 您需要处理其中任何一种情况吗?

  1. The client is running, but the server is not responding, and you want to know whether the unresponsive server is on a remote machine. 客户端正在运行,但是服务器没有响应,您想知道无响应的服务器是否在远程计算机上。
  2. The client and the server are running in two distinct virtual machines on the same host machine, and you want to report that as "running on the same machine." 客户端和服务器在同一主机上的两个不同的虚拟机中运行,并且您希望将其报告为“在同一台计算机上运行”。
  3. The client is running in a virtual machine hosted by the same machine as the server is running on, and you want to report that as "running on the same machine." 客户端在与服务器运行在同一台计算机上托管的虚拟机中运行,并且您希望将其报告为“在同一台计算机上运行”。
  4. The client and the server are running on uncoordinated networks and both might have been assigned the same name. 客户端和服务器在不协调的网络上运行,并且可能都被分配了相同的名称。
  5. The server is possibly hostile, and will attempt to deceive the client. 服务器可能是敌对的,并且将尝试欺骗客户端。

The network card will have a unique MAC. 网卡将具有唯一的MAC。 If both server and client report the same MAC then they are using the same network card. 如果服务器和客户端都报告相同的MAC,则它们正在使用相同的网卡。 If both client and server are running in different virtual machines but using the same network card, do you consider them running on the same machine or different machines? 如果客户端和服务器都在不同的虚拟机上运行,​​但使用相同的网卡,那么您是否认为它们在同一台计算机上运行?

Windows networking requires computer names to be unique, so calling the GetComputerName api and having the client and server swap names (and compare the received name to the name they see) should suffice. Windows网络要求计算机名称必须唯一,因此调用GetComputerName api并具有客户端和服务器交换名称(并将接收到的名称与他们看到的名称进行比较)就足够了。 If the client and server can start up independently of one another then you'll need some sort of protocol for this process. 如果客户端和服务器可以彼此独立地启动,则此过程需要某种协议。 It seems logical for the client to initiate the exchange, and the server to only send its name when it has received a name from a client. 客户端发起交换似乎是合乎逻辑的,并且服务器仅在收到客户端的名称后才发送其名称。 The client can then abort the connection if it sees the same name. 如果客户端看到相同的名称,则可以中止连接。

I believe most virtual machine systems will allow the virtual machine to have its own name, so it should still be possible for you to test on virtual machines. 我相信大多数虚拟机系统都会允许虚拟机使用自己的名称,因此您仍然可以在虚拟机上进行测试。 However I don't have extensive experience of all the virtualisation technologies out there, so can't say for sure. 但是我对所有的虚拟化技术没有丰富的经验,因此不能肯定地说。

how about trying to establish a loopback tcp connection? 如何尝试建立回送TCP连接? or maybe checking for some lock file created by the server in a predefined folder... 或检查服务器在预定义文件夹中创建的一些锁定文件...

I don't know exactly how, but there's for sure something equivalent in Win32 to the /proc filesystem in Unix (I think there are free replacements for the windows taskmanager, maybe you could look at their sources) where you could search for your server process. 我不知道具体如何,但是可以肯定的是Win32中与Unix中的/ proc文件系统等效(我认为Windows Taskmanager有免费的替代品,也许您可​​以看一下它们的源代码),您可以在其中搜索服务器处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定Windows标识是对应于本地用户还是域用户? - How can I determine if a Windows Identity corresponds to a local or a domain user? 如何确定Windows上“最窄”的字体? - How do I determine the “narrowest” font on Windows? 如何使用Java将文件从一台Windows计算机复制到另一台Windows计算机文件夹 - How do i copy a file from one windows machine to other windows machine folder using java 如何确定可移动驱动器上安装的Windows版本 - How do I determine the Windows version installed on a removable drive 如何在C#中以编程方式确定Windows 7的子版本? - How do I determine sub versions of Windows 7 programatically in C#? 如何确定 Windows 的“下载文件夹”路径? - How do I determine the Windows 'Download folder' path? 如何确定 Windows 10 上可执行二进制文件的体系结构 - How do I determine the architecture of an executable binary on Windows 10 如何在Windows 7计算机上的Eclipse中更改超链接颜色? - How do I change hyperlink colors in Eclipse on a Windows 7 machine? 如何在Windows计算机上开始使用MPI - How do I get started on MPI on windows machine 如何在我的 Windows 机器上找到 JDK 的安装位置? - How do I find where JDK is installed on my windows machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM