Advertisement
A_GUES

C AdBlocker

May 30th, 2023 (edited)
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. // List of ad domains to block
  6. const char* blocked_domains[] = {
  7.     "adserver.com",
  8.     "adservice.net",
  9.     "exampleads.com"
  10. };
  11.  
  12. int main() {
  13.     // Simulating network requests
  14.     const char* requests[] = {
  15.         "https://example.com",
  16.         "https://adserver.com/ad1",
  17.         "https://exampleads.com/banner"
  18.     };
  19.    
  20.     int num_requests = sizeof(requests) / sizeof(requests[0]);
  21.     int num_domains = sizeof(blocked_domains) / sizeof(blocked_domains[0]);
  22.    
  23.     // Check each request
  24.     for (int i = 0; i < num_requests; i++) {
  25.         int blocked = 0;
  26.        
  27.         // Check against each blocked domain
  28.         for (int j = 0; j < num_domains; j++) {
  29.             if (strstr(requests[i], blocked_domains[j]) != NULL) {
  30.                 blocked = 1;
  31.                 break;
  32.             }
  33.         }
  34.        
  35.         // Print the result
  36.         printf("%s: %s\n", requests[i], blocked ? "Blocked" : "Allowed");
  37.     }
  38.    
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement