public IPPrefix(IpPrefixType type, string RegionOrO365Service, string pStrRawPrefix) { Type = type; if (type == IpPrefixType.Azure || type == IpPrefixType.AzureChina) { Region = RegionOrO365Service; O365Service = null; } else { Region = null; O365Service = RegionOrO365Service; } RawPrefix = pStrRawPrefix; // if no / is present, add /32 if (RawPrefix.IndexOf("/") == -1) { RawPrefix = RawPrefix + "/32"; } RawPrefixSubnet = RawPrefix.Substring(0, RawPrefix.IndexOf("/")); Mask = Convert.ToInt32(RawPrefix.Substring(RawPrefix.IndexOf("/") + 1)); var subnetParts = RawPrefixSubnet.Split('.'); UInt32 subnetDecimal = (UInt32)Convert.ToInt32(subnetParts[0]) * 256 * 256 * 256; subnetDecimal += (UInt32)Convert.ToInt32(subnetParts[1]) * 256 * 256; subnetDecimal += (UInt32)Convert.ToInt32(subnetParts[2]) * 256; subnetDecimal += (UInt32)Convert.ToInt32(subnetParts[3]); FirstIP = subnetDecimal; }
public IPPrefix(string RawPrefix) { this.RawPrefix = RawPrefix; RawPrefixSubnet = this.RawPrefix.Substring(0, this.RawPrefix.IndexOf("/")); Mask = Convert.ToInt32(this.RawPrefix.Substring(this.RawPrefix.IndexOf("/") + 1)); #region FirstIp conversion var subnetParts = RawPrefixSubnet.Split('.'); UInt32 subnetDecimal = (UInt32)Convert.ToInt32(subnetParts[0]) * 256 * 256 * 256; subnetDecimal += (UInt32)Convert.ToInt32(subnetParts[1]) * 256 * 256; subnetDecimal += (UInt32)Convert.ToInt32(subnetParts[2]) * 256; subnetDecimal += (UInt32)Convert.ToInt32(subnetParts[3]); FirstIP = subnetDecimal; #endregion }