我有一个IP地址,我想计算相应的子网掩码。可以给我一些示例IP及其子网掩码..我使用过这段代码..这是正确的吗?
static public string ReturnSubnetmask(String ipaddress)
{
uint firstOctet = ReturnFirtsOctet(ipaddress);
if (firstOctet >= 0 && firstOctet <= 127)
return "255.0.0.0";
else if (firstOctet >= 128 && firstOctet <= 191)
return "255.255.0.0";
else if (firstOctet >= 192 && firstOctet <= 223)
return "255.255.255.0";
else return "0.0.0.0";
}
static public uint ReturnFirtsOctet(string ipAddress)
{
System.Net.IPAddress iPAddress = System.Net.IPAddress.Parse(ipAddress);
byte[] byteIP = iPAddress.GetAddressBytes();
return (uint)byteIP[0];
}