static void Main(string[] args) { // Variable declaration List <IPPrefix> ipPrefixesInput = new List <IPPrefix>(); List <IPPrefix> ipPrefixesOutput = new List <IPPrefix>(); // Load the XML file into ranges ipPrefixesInput = Downloader.Download(); // add default private network prefixes //ipPrefixesInput.Add(new IPPrefix("0.0.0.0/8")); //ipPrefixesInput.Add(new IPPrefix("10.0.0.0/8")); //ipPrefixesInput.Add(new IPPrefix("172.16.0.0/12")); //ipPrefixesInput.Add(new IPPrefix("169.254.0.0/16")); //ipPrefixesInput.Add(new IPPrefix("192.168.0.0/16")); //ipPrefixesInput.Add(new IPPrefix("224.0.0.0/3")); //Generator.Dedupe(ipPrefixesInput); //ipPrefixesOutput ipPrefixesOutput = Generator.Summarize(ipPrefixesInput); var testPrefix = new IPPrefix("216.32.180.38/31"); var solutionPrefix = Generator.GetContainingPrefix(testPrefix, ipPrefixesOutput); // Order the ranges by increasing network ID //ipPrefixesOutput = Generator.Not(ipPrefixesInput); //foreach (IPPrefix l_currentPrefix in ipPrefixesOutput) //{ // Console.Write(String.Concat(l_currentPrefix.ReadableIP,"/",l_currentPrefix.Mask,"\n")); //} if (solutionPrefix != null) { string prefixLocation; if (solutionPrefix.Region != null) { prefixLocation = solutionPrefix.Region; } else { prefixLocation = solutionPrefix.O365Service; } Console.Write("Found " + testPrefix.ToString() + " in : \n" + solutionPrefix.ToString() + ";" + prefixLocation + "\n"); } else { Console.Write("Unable to find prefix " + testPrefix.ToString() + " in list.\n"); } Console.Write("Done!\n"); Console.ReadKey(); //Debugger.Break(); }
// GET api/<controller> public IEnumerable <string> Get([FromUri] string inputIP) { try { // try to resolve the IP address IPAddress[] ipAddList = Dns.GetHostAddresses(inputIP); // String to build output var resultstring = inputIP + " resolves to ..." + System.Environment.NewLine; // Look for each IP under the hostname... foreach (var ipAdd in ipAddList) { var inputPrefix = new IPPrefix(ipAdd.ToString() + "/32"); var outputPrefix = FindPrefixHelper.FindPrefix(inputPrefix); if (outputPrefix != null) { string prefixLocation = string.Empty; // Check if it's part of an Azure region or O365 service if (outputPrefix.Region != null) { prefixLocation = " in region " + outputPrefix.Region; } else { prefixLocation = " in Office 365 service " + outputPrefix.O365Service; } //Build the string result resultstring += (inputPrefix.ToString() + " is part of " + outputPrefix.ToString() + prefixLocation + System.Environment.NewLine); } else { resultstring += (inputPrefix.ToString() + " but isn't part of our prefix lists." + System.Environment.NewLine); } } return(new string[] { resultstring }); } catch (Exception ex) { return(new string[] { "Invalid IP address or hostname : " + ex.Message }); } }