Skip to content

Instantly share code, notes, and snippets.

View SibeeshVenu's full-sized avatar
🙂
Learning and Sharing

Sibeesh Venu SibeeshVenu

🙂
Learning and Sharing
View GitHub Profile
@SibeeshVenu
SibeeshVenu / IPNetworkContains.cs
Created October 13, 2023 09:31
IPNetwork Contains Method
/// <summary>
/// Determine whether a given The <see cref="IPAddress"/> is part of the IP network.
/// </summary>
/// <param name="address">The <see cref="IPAddress"/>.</param>
/// <returns><see langword="true"/> if the <see cref="IPAddress"/> is part of the IP network. Otherwise, <see langword="false"/>.</returns>
public bool Contains(IPAddress address)
{
if (Prefix.AddressFamily != address.AddressFamily)
{
return false;
@SibeeshVenu
SibeeshVenu / IpActionFilter.cs
Created October 13, 2023 09:08
IP filter ActionFilterAttribute with Contains method from .NET8 IPNetwork class.
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Net;
namespace DotNetIpFilter.Services
{
/// <summary>
/// IpActionFilter
/// </summary>
public class IpActionFilter : ActionFilterAttribute
@SibeeshVenu
SibeeshVenu / IpActionFilterTest.cs
Last active August 12, 2023 07:09
Tests for IpActionFilter
using System.Net;
using NSubstitute;
using Microsoft.Extensions.Logging;
using DotNetIpFilter.Services;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
@SibeeshVenu
SibeeshVenu / WeatherForecastController.cs
Last active August 12, 2023 07:11
WeatherForecastController.cs with IpActionFilter ServiceFilter
using DotNetIpFilter.Services;
using Microsoft.AspNetCore.Mvc;
namespace DotNetIpFilter.Controllers
{
[ApiController]
[Route("[controller]")]
[ServiceFilter(typeof(IpActionFilter))]
public class WeatherForecastController : ControllerBase
{
@SibeeshVenu
SibeeshVenu / Program.cs
Created August 11, 2023 13:14
Program file with AddHostedService<IpHostedService>()
using DotNetIpFilter.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
@SibeeshVenu
SibeeshVenu / IpHostedService.cs
Last active August 11, 2023 13:29
IpHostedService that implements IHostedService
namespace DotNetIpFilter.Services
{
/// <summary>
/// IpHostedService
/// </summary>
public class IpHostedService: IHostedService
{
/// <summary>
/// The service provider
/// </summary>
@SibeeshVenu
SibeeshVenu / IIpFilterService.cs
Last active August 11, 2023 13:30
IIpFilterService.cs
namespace DotNetIpFilter.Services
{
/// <summary>
/// IIpFilterService
/// </summary>
public interface IIpFilterService
{
/// <summary>
/// GetAdminSafeIpList
/// </summary>
@SibeeshVenu
SibeeshVenu / IpFilterService.cs
Last active August 12, 2023 07:10
IpFilterService that implements IIpFilterService
namespace DotNetIpFilter.Services
{
/// <summary>
/// IpFilterService
/// </summary>
public class IpFilterService : IIpFilterService
{
/// <summary>
/// Logger
/// </summary>
@SibeeshVenu
SibeeshVenu / IpActionFilter.cs
Last active August 12, 2023 07:12
IpActionFilter that implements ActionFilterAttribute
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Net;
namespace DotNetIpFilter.Services
{
/// <summary>
/// IpActionFilter
/// </summary>
public class IpActionFilter : ActionFilterAttribute
@SibeeshVenu
SibeeshVenu / main.py
Created October 1, 2022 13:59
Main python code
from notify_teams import notify_to_teams
from keyvault_helper import get_key_vault_secret
kv_secret_name = ''
kv_name = ''
web_hook_url = get_key_vault_secret(kv_name, kv_secret_name)
message = 'Hi, this message is from the Python application that uses the Webhook connector.'
notify_to_teams(message, web_hook_url.value, kv_secret_name)