查找由Dns.GetHostEntry返回的正确IP地址 [英] Find correct Ip address returned by Dns.GetHostEntry

查看:69
本文介绍了查找由Dns.GetHostEntry返回的正确IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设同一网络上有两台计算机,分别为com1和com2.

Suppose there are 2 computers on same network, named com1 and com2.

在com1上,如果我打电话

On com1, if I call

Dns.GetHostEntry("com2")

确实,它仅返回1个IP地址,例如192.168.1.2,我可以使用它与com2进行通信.但是,如果我致电

surely enough, it returns only 1 ip address, like 192.168.1.2, which I could use it to communicate with com2. However, if I call

Dns.GetHostEntry("com1")

它将返回所有个IP地址(192.168.1.1(我想要的一个)以及其他地址,例如169.254.100.50(虚拟机地址,我需要对此进行过滤))

It will return all ip addresses (192.168.1.1(the one I want) as well as other addresses like 169.254.100.50 (vm address, I need to filter this out))

问题是,在这种情况下,如何获得com1的唯一真实" ip地址?

The question is, how can I get a unique "real" ip address for com1 in this case?

谢谢.

推荐答案

经过一些研究,这个问题实际上很难回答.如果"com1"具有多个NIC,则很难找到它用于与"com2"通信的NIC,我发现

After some research this question is actually hard to answer. If "com1" has multiple NICs, it is hard to find which NIC it uses to communicate with "com2", I have found this SO link to get address on NICs that are connected to internet, VM address will not connect to internet. Obviously asking "com1" itself to find which NIC it uses to connect to "com2" is hard,should rather asking "com2" instead.

这篇关于查找由Dns.GetHostEntry返回的正确IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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