Exemplo n.º 1
0
        public static void Run([TimerTrigger("0 */30 * * * *")] TimerInfo myTimer, ILogger log, ExecutionContext context)
        {
            // Log the start
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            // Temporarily disable the task
            log.LogInformation($"This task has been temporarily disabled");
            return;


            // Initialize the configuration object
            var config = new ConfigurationBuilder()
                         .SetBasePath(context.FunctionAppDirectory)
                         .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                         .AddEnvironmentVariables()
                         .Build();

            // Get the storage account information
            string storageAccountName = config["StorageAccountName"];
            string storageAccountKey  = config["StorageAccountKey"];

            // Create the resources
            Azure az = new Azure(storageAccountName, storageAccountKey);

            // Read the RBLs from the configuration
            List <RBL> MyRBLs = az.GetRBLs();

            // Read the hosts from the configuration
            List <Host> MyHosts = az.GetHosts();

            // Process each host
            foreach (Host host in MyHosts)
            {
                log.LogInformation($"Processing host: {host.Name}");

                foreach (RBL l in MyRBLs)
                {
                    RBLHostResult r = l.QueryHost(host.IP);

                    if (r.IsListed)
                    {
                        log.LogInformation($"\tHost {r.Host} is listed on {r.RBL}");
                    }
                    else
                    {
                        log.LogInformation($"\tHost {r.Host} is NOT listed on {r.RBL}");
                    }
                }
            }

            // Log the end
            log.LogInformation($"C# Timer trigger function completed at: {DateTime.Now}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Query a RBL
        /// </summary>
        /// <param name="IP"></param>
        /// <returns></returns>
        public RBLHostResult QueryHost(string IP)
        {
            // Create the result object
            RBLHostResult result = new RBLHostResult(this.Name, IP);

            // Create the record to query
            string[] parts  = IP.Split('.');
            string   record = parts[3] + '.' + parts[2] + '.' + parts[1] + '.' + parts[0] + '.' + FQDN;

            // Query the list
            try
            {
                IPHostEntry host = Dns.GetHostEntry(record);

                if (host.AddressList != null)
                {
                    // The host is found
                    result.IsListed = true;
                    result.Details  = string.Empty;
                }
            }
            catch (Exception e)
            {
                if (e.Message.Equals("No such host is known"))
                {
                    result.IsListed = false;
                    result.Details  = string.Empty;
                }
            }

            if (result.IsListed)
            {
                // Query the txt record
            }

            // Return the result
            return(result);
        }