Example #1
0
        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;
        }
Example #2
0
        private static List <IPPrefix> AddXMLMSInputFileAzure(string downloadURL, IpPrefixType type)
        {
            string          dlUrl      = string.Empty;
            string          dlContent  = string.Empty;
            List <IPPrefix> IPPrefixes = new List <IPPrefix>();

            using (var wc = new WebClient())
            {
                dlUrl = wc.DownloadString(downloadURL);
                var result = Regex.Match(dlUrl, "url=(.*)\"");
                dlUrl     = result.Groups[1].Value;
                dlContent = wc.DownloadString(dlUrl);
            }

            //For using when offline testing
            //using (streamReader = new StreamReader(@"c:\Users\omartin2\Downloads\PublicIPs_20160719.xml", Encoding.UTF8))
            //{
            //    dlContent = streamReader.ReadToEnd();
            //}

            var xContent = XDocument.Load(new StringReader(dlContent));     // XML document containing the list

            // Looing in the document sections
            foreach (var xRegion in xContent.Elements().First().Elements())
            {
                foreach (var xIPPrefix in xRegion.Elements())
                {
                    var prefix = new IPPrefix(
                        type,
                        xRegion.Attributes("Name").First().Value,
                        xIPPrefix.Attributes("Subnet").First().Value
                        );
                    IPPrefixes.Add(prefix);
                }
            }
            return(IPPrefixes);
        }