// ==================================================================== // 602TechSec List Management API - C# Quick Start Example // ==================================================================== // This example demonstrates the most common operations for the // List Management API. Copy and modify this code for your needs. // // REQUIREMENTS: // - .NET Framework 4.5+ or .NET Core 3.1+ // - Newtonsoft.Json (Install via NuGet: Install-Package Newtonsoft.Json) // // SETUP: // 1. Replace "your-api-key-here" with your actual API key // 2. Run the example to see the API in action // ==================================================================== using System; using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; namespace TechSec602.Examples { class QuickStartExample { private const string ApiKey = "your-api-key-here"; private const string BaseUrl = "https://sec.602.tech"; static async Task Main(string[] args) { Console.WriteLine("602TechSec List Management API - Quick Start"); Console.WriteLine("=" + new string('=', 50)); Console.WriteLine(); try { // Example 1: Add an IP to whitelist Console.WriteLine("1. Adding IP to whitelist..."); await AddIpToWhitelist("192.168.1.100"); // Example 2: Add a host to blacklist Console.WriteLine("\n2. Adding host to blacklist..."); await AddHostToBlacklist("malicious.com"); // Example 3: Bulk add multiple IPs Console.WriteLine("\n3. Bulk adding IPs..."); var ips = new List { "10.0.0.1", "10.0.0.2", "10.0.0.3" }; await BulkAddIps(ips); // Example 4: Check if IP is in whitelist Console.WriteLine("\n4. Checking if IP is whitelisted..."); var isWhitelisted = await CheckIpWhitelisted("192.168.1.100"); Console.WriteLine($" IP is whitelisted: {isWhitelisted}"); // Example 5: Get all lists Console.WriteLine("\n5. Retrieving all lists..."); await GetAllLists(); // Example 6: Remove IP from whitelist Console.WriteLine("\n6. Removing IP from whitelist..."); await RemoveIpFromWhitelist("192.168.1.100"); Console.WriteLine("\nAll examples completed successfully!"); } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); } Console.WriteLine("\nPress any key to exit..."); Console.ReadKey(); } /// /// Example 1: Add an IP address to whitelist /// static async Task AddIpToWhitelist(string ipAddress) { using (var client = new HttpClient()) { var request = new { apiKey = ApiKey, ipAddress = ipAddress, listType = "whitelist" }; var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"{BaseUrl}/api/listmanagement/ip/add", content); var resultJson = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject(resultJson); Console.WriteLine($" Success: {result.Success}"); Console.WriteLine($" Message: {result.Message}"); } } /// /// Example 2: Add a host to blacklist /// static async Task AddHostToBlacklist(string host) { using (var client = new HttpClient()) { var request = new { apiKey = ApiKey, host = host, listType = "blacklist" }; var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"{BaseUrl}/api/listmanagement/host/add", content); var resultJson = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject(resultJson); Console.WriteLine($" Success: {result.Success}"); Console.WriteLine($" Message: {result.Message}"); } } /// /// Example 3: Bulk add multiple IP addresses /// static async Task BulkAddIps(List ipAddresses) { using (var client = new HttpClient()) { var request = new { apiKey = ApiKey, entries = ipAddresses, entryType = "ip", listType = "whitelist" }; var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"{BaseUrl}/api/listmanagement/bulk/add", content); var resultJson = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject(resultJson); Console.WriteLine($" Success Count: {result.SuccessCount}"); Console.WriteLine($" Failure Count: {result.FailureCount}"); if (result.FailedEntries?.Count > 0) { Console.WriteLine($" Failed Entries: {string.Join(", ", result.FailedEntries)}"); } } } /// /// Example 4: Check if IP is in whitelist /// static async Task CheckIpWhitelisted(string ipAddress) { using (var client = new HttpClient()) { var request = new { apiKey = ApiKey, entry = ipAddress, entryType = "ip" }; var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"{BaseUrl}/api/listmanagement/check", content); var resultJson = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject(resultJson); return result.InWhitelist; } } /// /// Example 5: Get all lists /// static async Task GetAllLists() { using (var client = new HttpClient()) { var response = await client.GetAsync($"{BaseUrl}/api/listmanagement/lists?apiKey={ApiKey}"); var resultJson = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject(resultJson); Console.WriteLine($" IP Whitelist: {result.IpWhitelist?.Count ?? 0} entries"); if (result.IpWhitelist != null) { foreach (var ip in result.IpWhitelist) { Console.WriteLine($" - {ip}"); } } Console.WriteLine($" IP Blacklist: {result.IpBlacklist?.Count ?? 0} entries"); if (result.IpBlacklist != null) { foreach (var ip in result.IpBlacklist) { Console.WriteLine($" - {ip}"); } } Console.WriteLine($" Host Whitelist: {result.HostWhitelist?.Count ?? 0} entries"); Console.WriteLine($" Host Blacklist: {result.HostBlacklist?.Count ?? 0} entries"); } } /// /// Example 6: Remove IP from whitelist /// static async Task RemoveIpFromWhitelist(string ipAddress) { using (var client = new HttpClient()) { var request = new { apiKey = ApiKey, ipAddress = ipAddress, listType = "whitelist" }; var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"{BaseUrl}/api/listmanagement/ip/remove", content); var resultJson = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject(resultJson); Console.WriteLine($" Success: {result.Success}"); Console.WriteLine($" Message: {result.Message}"); } } #region Response Models public class ApiResponse { public bool Success { get; set; } public string Message { get; set; } public string Entry { get; set; } public string ListType { get; set; } public DateTime Timestamp { get; set; } } public class BulkApiResponse { public bool Success { get; set; } public string Message { get; set; } public int SuccessCount { get; set; } public int FailureCount { get; set; } public List FailedEntries { get; set; } public DateTime Timestamp { get; set; } } public class CheckEntryResponse { public bool Success { get; set; } public string Entry { get; set; } public bool InWhitelist { get; set; } public bool InBlacklist { get; set; } public string Message { get; set; } public DateTime Timestamp { get; set; } } public class ListContentsResponse { public bool Success { get; set; } public List IpWhitelist { get; set; } public List IpBlacklist { get; set; } public List HostWhitelist { get; set; } public List HostBlacklist { get; set; } public int TotalWhitelistCount { get; set; } public int TotalBlacklistCount { get; set; } public DateTime Timestamp { get; set; } } #endregion } }