// ====================================================================
// EXAMPLE FILE - FOR REFERENCE ONLY
// This is a sample helper class you can use in your own C# projects
// to integrate with the 602TechSec List Management API
// ====================================================================
using System;
using System.Net;
using System.Text.RegularExpressions;
namespace YourProject.Helpers
{
///
/// Helper class for managing whitelist and blacklist entries with 602TechSec API
/// Copy this class into your project and customize as needed
///
public class ListManagementHelper
{
private readonly string _apiKey;
private readonly string _baseUrl = "https://sec.602.tech";
public ListManagementHelper(string apiKey)
{
_apiKey = apiKey;
}
///
/// Validates an IP address format
///
public bool IsValidIpAddress(string ipAddress)
{
if (string.IsNullOrWhiteSpace(ipAddress))
return false;
return IPAddress.TryParse(ipAddress, out _);
}
///
/// Validates a host/domain format
///
public bool IsValidHost(string host)
{
if (string.IsNullOrWhiteSpace(host))
return false;
// Allow wildcards like *.example.com
var pattern = @"^(\*\.)?([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$";
return Regex.IsMatch(host, pattern);
}
///
/// Normalizes IP address (removes extra spaces, validates format)
///
public string NormalizeIpAddress(string ipAddress)
{
if (!IsValidIpAddress(ipAddress))
return null;
return IPAddress.Parse(ipAddress).ToString();
}
///
/// Normalizes host (converts to lowercase, removes protocol)
///
public string NormalizeHost(string host)
{
if (string.IsNullOrWhiteSpace(host))
return null;
// Remove protocol if present
host = Regex.Replace(host, @"^https?://", "", RegexOptions.IgnoreCase);
// Remove trailing slash
host = host.TrimEnd('/');
// Convert to lowercase
host = host.ToLowerInvariant();
return IsValidHost(host) ? host : null;
}
///
/// Validates CIDR notation
///
public bool IsValidCidr(string cidr)
{
if (string.IsNullOrWhiteSpace(cidr))
return false;
var parts = cidr.Split('/');
if (parts.Length != 2)
return false;
// Validate IP part
if (!IsValidIpAddress(parts[0]))
return false;
// Validate subnet mask (0-32 for IPv4, 0-128 for IPv6)
if (!int.TryParse(parts[1], out int mask))
return false;
var ip = IPAddress.Parse(parts[0]);
var maxMask = ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 ? 128 : 32;
return mask >= 0 && mask <= maxMask;
}
///
/// Normalizes CIDR notation
///
public string NormalizeCidr(string cidr)
{
if (!IsValidCidr(cidr))
return null;
var parts = cidr.Split('/');
var normalizedIp = NormalizeIpAddress(parts[0]);
return $"{normalizedIp}/{parts[1]}";
}
///
/// Validates API key format
///
public bool IsValidApiKey(string apiKey)
{
if (string.IsNullOrWhiteSpace(apiKey))
return false;
// API keys should be at least 16 characters
return apiKey.Length >= 16;
}
// Add your API integration methods here
// See full examples in ListManagementClient.cs.example
}
}