财产“地址清单”是怎样的?有序? [英] How is the property "addresslist" ordered?

查看:98
本文介绍了财产“地址清单”是怎样的?有序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello社区,



我没有技术问题,但我正在考虑一个问题,以确保我的应用程序正常运行。



到目前为止,我使用以下代码获取主机的IP地址:

Hello community,

I don´t have a technical issue but a question which I am thinking about to make sure that my application works properly.

Until now I´m using the following code to get the IP address of a host:

Dim address As System.Net.IPAddress = System.Net.Dns.GetHostEntry("computername").AddressList(0)

到目前为止,返回的IP地址始终是正确的,但我想确保它确实是正确的。我假设简单地使用AddressList中的第一个条目(或者我错了吗?)并不是没有问题。



所以我的问题是AddressList将如何收集地址后订购。它是按字母顺序迭代网络接口设备并将每个IP添加到AddressList吗?或者它们是否会被IP密码订购?



有没有人有想法?它是否定义了?



提前谢谢大家!



我有什么尝试过:



我读过 IPHostEntry.AddressList属性(System.Net)| Microsoft Docs [ ^ ]但没有找到答案。

So far the returned IP address was always the correct one but I want to make sure that it´s really the correct one. I assume that it´s not unproblematic to simply use the first entry in the AddressList (or am I wrong?).

So my question is how the AddressList will be orderd after gathering the addresses. Is it iterating the network interface devices alphabetically and add each IP to the AddressList? Or will they be ordered by the IP octects?

Does anyone have an idea? Is it defined at all?

Thank you all in advance!

What I have tried:

I read IPHostEntry.AddressList Property (System.Net) | Microsoft Docs[^] but didn´t find the answer.

推荐答案

正如我在问题评论中提到的,我相信它没有订购。当它(它们)被检索时它会得到地址。



MSDN文档 [ ^ ]:

As i mentioned in the comment to the question, i do believe it's not ordered. It gets adress(es) as it(they) is(are) retrieved.

See MSDN documentation[^]:
Quote:

GetHostEntry方法在DNS服务器中查询与主机名或IP地址关联的IP地址。

The GetHostEntry method queries a DNS server for the IP address that is associated with a host name or IP address.





对于eaxmple:



For eaxmple:

Dim addresses = System.Net.Dns.GetHostEntry("www.contoso.com").AddressList



返回:


returns:

Address    AddressFamily ScopeId           IsIPv6Multicast IsIPv6LinkLocal IsIPv6SiteLocal IsIPv6Teredo IsIPv4MappedToIPv6
3143620456 InterNetwork  6SocketException4 False           False           False           False        False 
953066548  InterNetwork  6SocketException4 False           False           False           False        False 


我真的不相信可以有鉴于大局,这是正确的顺序。



1.可以为网络接口分配多个IP地址。

2.多个网络接口可以安装在计算机上。

3.计算机可以在多个网络上。

4.多个DNS服务器可以有同一台计算机的条目,具有不同的地址。



所以你用 GetHostList 获得的是从任何DNS服务器上找到的IP地址列表。



具有多个IP的连接设备的示例:

- 回到90年代,在2条电话线上有2个调制解调器,桥接;增加带宽

- 智能手机;有一个46连接以及WiFi和BlueTooth

- 您的家用路由器;拥有公共IP,私人有线IP和私人WiFi IP



因此....如果你在家里使用命令运行应用程序,你会可能会得到不同的答案取决于使用的网络;例如WiFi或强线
I really do not believe there can be a correct order for this, given the big picture.

1. Multiple IP Addresses can be assigned to a Network Interface.
2. Multiple Network Interfaces can be installed on a computer.
3. A computer can be on multiple networks.
4. Multiple DNS servers can have entries for the same computer, with different addresses.

So what you get with GetHostList is a list of IP addresses it found from whatever DNS server(s) answered.

Examples of a connected device having multiple IPs:
- Back in the 90's have 2 modems on 2 phone lines, bridged; to increase bandwidth
- A smartphone; having a 46 connection along with WiFi and BlueTooth
- Your home router; having a public IP, a private wired IP, and a private WiFi IP

Thus.... if you ran an app using the command at home, you would most likely get different answers depending on what network was being used; WiFi or hardline for example


非常感谢您的支持!我在这里找到答案:



主机名时ping如何工作有多个IP地址? - 服务器故障 [ ^ ]



简而言之:

AddressList中项目的顺序不是随机的,而是在DNS服务器上配置的。根据我的理解,这意味着在公司环境中我可以在AddressList属性上使用索引,因为DNS服务器的答案顺序应始终相同。
Many thanks to all of your for your support! I found the answer here:

How does ping work when a host name has multiple ip addresses? - Server Fault[^]

In short:
The order of the items in AddressList is not random but it´s configured on the DNS server. For my understanding that means that in a company environment I can use an index on the AddressList property because the DNS server answer order should always be the same.


这篇关于财产“地址清单”是怎样的?有序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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