我尝试转换掩码IP地址的格式(称为通配符掩码)。 我想,例如,反转掩码IP地址(通配符掩码)
- SubnetMask 0.0.0.3应返回255.255.255.252。
- 子网掩码0.0.1.255应该返回255.255.254.0
有人有任何线索我怎么能做到这一点? 理论上,它应该很简单,因为我只需要反转字节中的所有位。 我认为我的函数反转位不工作?我怎么能做到这一点? 谢谢你! :)
//Retreive IP Subnet Mask (ex: Format 0.0.0.255)
IPAddress SubnetMask = IPAddress.Parse(template_script[line_delimiter].Split(' ')[2]);
//Retreive bytes array of Mask
byte[] bytes = SubnetMask.GetAddressBytes();
//Reverse all bit in bytes
byte[] reversed = Function.InvertBits(bytes);
//Retreive IP Address of inverted byte array
IPAddress SubnetMask_inverted = new IPAddress(reversed);
MessageBox.Show("Subnet original: " + SubnetMask.ToString() + "\nSubnet inverted : " + SubnetMask_inverted.ToString());
你只是想'255 x'每个字节? – Blorgbeard