ip地址。[尝试]解析解析192.168到192.0.0.168地址、ip

由网友(爱人不过是碍人)分享简介:我有以下情形:ip地址的IP;IPAddress.TryParse(192.168,出IP);如果(IP == NULL){//做一些与IP}我希望解析失败,而是被解析为192.0.0.168。我在想什么吗? (IPAddress.Parse的工作方式相同)解决方案 在文档,其中包括类似的例子给你的,是prett...

我有以下情形:

  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
 

怎么查路由器IP地址 192.168.1.1 的解决方案

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

阅读全文

相关推荐

最新文章