ip地址。[尝试]解析解析192.168到192.0.0.168 [英] IPAddress.[Try]Parse parses 192.168 to 192.0.0.168

查看:250
本文介绍了ip地址。[尝试]解析解析192.168到192.0.0.168的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情形:

  ip地址的IP;
IPAddress.TryParse(192.168,出IP);
如果(IP == NULL){//做一些与IP}
 

我希望解析失败,而是被解析为192.0.0.168。我在想什么吗? (IPAddress.Parse的工作方式相同)

解决方案

文档,其中包括类似的例子给你的,是pretty的明确的:

  

份的数量(每一个部分是由一个周期分隔)在ipString   确定如何将IP地址构成。单组分地址   直接存储在网络地址。两部分地址,方便   指定一个A类地址,把领导参加了第一   字节和后沿部分中的最右侧的三个字节的   网络地址。一个三部分地址,方便指定   B类地址,把所述第一部分中的第一字节,第二   部分中的第二个字节,并且在最右边的2的最后部分   的网络地址的字节。

 部分和榜样ipString IPv4地址ip地址数
================================================== ==================
1  - 655360.0.255.255
2  - 20.220.0.0.2
2  - 20.6553520.0.255.255
3  - 128.1.2128.1.0.2
 

I have the following scenario:

IPAddress ip;
IPAddress.TryParse("192.168", out ip);    
if(ip == null){//do something with IP}

I would expect the parsing to fail, instead it is parsed as "192.0.0.168". What am I missing here? (IPAddress.Parse works the same)

解决方案

The documentation, which includes similar examples to yours, is pretty clear:

The number of parts (each part is separated by a period) in ipString determines how the IP address is constructed. A one part address is stored directly in the network address. A two part address, convenient for specifying a class A address, puts the leading part in the first byte and the trailing part in the right-most three bytes of the network address. A three part address, convenient for specifying a class B address, puts the first part in the first byte, the second part in the second byte, and the final part in the right-most two bytes of the network address.

Number of parts and example ipString      IPv4 address for IPAddress    
====================================================================
1 -- "65536"                              0.0.255.255
2 -- "20.2"                               20.0.0.2
2 -- "20.65535"                           20.0.255.255
3 -- "128.1.2"                            128.1.0.2

这篇关于ip地址。[尝试]解析解析192.168到192.0.0.168的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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