如何区分两个IP是否属于同一台计算机?
我们在客户端的不同计算机上有一个主程序和代理(两者)。网络配置可以是任何类型(我们不知道)。代理连接到主程序,目前我们只能获取 IP 和计算机名称作为信息。如何区分两个IP是否属于同一台计算机?
计算机可能有多个以太网卡。
谢谢。
We have a master program and agents (both) on the customer side on different computers. The network configuration can be any type (we don't know). The agents connect to the master program and currently we only can get the IP and computer name as information. How do I distinguish if two IPs belong to the same computer?
Computers may have more than one ethernet cards.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
仅通过查看 IP 地址是无法判断的。
有些计算机具有唯一标识符,但您需要 JNI 才能访问它们,并且您的代码将非常特定于平台。生成 GUID 并将其写入计算机上临时文件夹中的文件可能是一个更好的主意。然后,在该计算机上运行的软件的所有实例都将读取相同的 GUID,并可以在建立连接时将此数据提供给服务器。
There is no way to tell just by looking at the IP addresses.
Some computers have unique identifiers, but you would need JNI to access them and your code would be very platform-specific. It might be a better idea to generate a GUID and write it to a file in a temp folder on the machine. Then, all instances of the software that run on that machine would read the same GUID and can provide this data to the server when a connection is made.
您可以修改代理以发送相关计算机的 MAC。除此之外,您无法真正确定它们是否相同。
You can modify the agents to send the MAC(s) of the machines in question. Beyond that, you can't really determine if they are the same.
你说你正在获取计算机名称 - 你不能根据该值进行重复数据删除吗?
通过网络,并且只给出 IP 地址,您无法辨别。 NAT 的工作方式以及当今的笔记本电脑和无线设备经常全天从一个网络跳到另一个网络这一事实,您所看到的只是该计算机面向公众的 IP 地址,该地址很可能在整个组或整个组织中共享机器。
除非您修改代理应用程序以包含唯一标识符(例如 MAC 地址 - 即使这样,它也只能告诉您这是一个唯一的 NIC,如果机器有多个 NIC,则不一定是唯一的机器),否则您就不走运了。 您无法仅根据 IP 地址确定唯一性。
不确定您的用例是什么,但如果用于应用程序内的禁止/跟踪操作,那么最好需要机器访问系统的某种唯一标识符(例如用户名),以便您知道可以禁止/跟踪应用程序的单个实例,或登录到应用程序的任何实例的单个用户,而不是尝试通过IP地址来解决此类问题。
You say you're getting the computer name - can't you de-duplicate based on that value?
From across a network, and given only an IP address, you can't tell. The way NAT works, and the fact that today's laptops and wireless devices often hop from network to network throughout the day, all you see is the public-facing IP address of that machine, which is very likely shared across a group, or entire organization of machines.
Unless you modify the agent application to also include a unique identifier (such as MAC address - which even then only tells you it's a unique NIC, not necessarily a unique machine if machines have multiple NICs), you're out of luck. You can't determine uniqueness from the IP address alone.
Not sure what your use case is, but if it's for banning/tracing actions within the application, then it's better to require some kind of unique identifier for the machine to access the system (such as a username) so you know that you can ban/trace a single instance of the app, or a single user logged into any instance of the app, rather than trying to solve that kind of a problem through IP addresses.
您可以在其机器中创建一个服务,该服务将公开唯一标识符。然后,您可以使用不同的 IP 作为主机名来调用该服务并比较这些值。
You could create a service in its machine that will expose a unique identifier. You could then call this service using different IPs as the host name and compare the values.