For retrieving the client IP under your Azure function with HTTP Trigger, you could use the following code snippet:
run.csx:
#r "System.Web"
using System.Web;
using System.Net;
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
{
var address = ((HttpContextWrapper)req.Properties["MS_HttpContext"]).Request.UserHostAddress;
log.Info($"Your client IP: {address}");
return req.CreateResponse(HttpStatusCode.OK, $"Your client IP: {address}");
}
For more details, you could refer to this issue.
so that I can block client ipaddress for a day, if user makes calls to api beyond the number of attempts and next day again I can unblock client ipaddress by taking all ipaddress from queue storage running timer trigger in cloud.
I would prefer to use table storage for storing the access logs for the specific IPs. You could set the PartitionKey
column to the Date, set RowKey
to the ClientIP
or ClientIP + ApiName
, also you could add other columns (Timestamp, TotalRequests, etc). Also, you could refer to Azure Storage Table Design Guide for designing your storage table.
For your azure function, you could use Storage table bindings and Table Storage SDK for reading request log for the specific IP and update the total request count for the specific IP. Moreover, here is a similar blog, you could refer to here.
UPDATE:
You could configure the logs to be stored in the file system or blob storage under the "MONITORING > Diagnostic logs" as follows:


For Application Logging (Filesystem), you could find the logs via kudu:

For Application Logging (Blob), you could leverage the Storage Explorer to retrieve your logs.