Solved VPN/Proxy Blocker

Unpaid Requests, Public Plugins
Post Reply
Pdv72
Member
Member
United States of America
Posts: 6
Joined: 4 years ago
Contact:

VPN/Proxy Blocker

#1

Post by Pdv72 » 3 years ago

Hi,
There is a plugin it's job to block any detected client who's using Proxy/VPN.
But the problem is that this plugin appears as "Running" But it does not doing it's job. like checking client and punishing fake client and the legit client don't gets punished.
Plugin Code:
  1. #include <amxmodx>
  2. #tryinclude <grip>
  3. #include <nvault>
  4.  
  5. #pragma semicolon 1
  6.  
  7. #if !defined _grip_included
  8.     #assert "gRIP module is required! https://dev-cs.ru/resources/650/"
  9. #endif
  10.  
  11. new g_szDataDir[PLATFORM_MAX_PATH];
  12. new g_hVault = INVALID_HANDLE;
  13.  
  14. public plugin_init() {
  15.     register_plugin("Proxy Check", "2.1", "juice, voed");
  16.    
  17.     if ((g_hVault = nvault_open("proxycheck")) == INVALID_HANDLE) {
  18.         set_fail_state("nvault Error: Vault wasn't opened!");
  19.         return;
  20.     }
  21.    
  22.     get_localinfo("amxx_datadir", g_szDataDir, charsmax(g_szDataDir));
  23.     add(g_szDataDir, charsmax(g_szDataDir), "/proxycheck");
  24.    
  25.     if (!dir_exists(g_szDataDir)) {
  26.         mkdir(g_szDataDir);
  27.     }
  28. }
  29.  
  30. public client_putinserver(id) {
  31.     if (is_user_bot(id) || is_user_hltv(id)) {
  32.         return;
  33.     }
  34.    
  35.     new netAddress[MAX_IP_LENGTH];
  36.     get_user_ip(id, netAddress, charsmax(netAddress), 1);
  37.  
  38.     if (netAddress[0] == 'l') {
  39.         return;
  40.     } else {
  41.         new buf[sizeof netAddress];
  42.  
  43.         copy(buf, charsmax(buf), netAddress);
  44.         replace_all(buf, charsmax(buf), ".", " ");
  45.        
  46.         new octets[4][4];
  47.         parse(buf, octets[0], charsmax(octets[]),
  48.             octets[1], charsmax(octets[]),
  49.             octets[2], charsmax(octets[]),
  50.             octets[3], charsmax(octets[]));
  51.                
  52.         new address = (str_to_num(octets[0]) << 24) |
  53.             (str_to_num(octets[1]) << 16) |
  54.             (str_to_num(octets[2]) << 8) |
  55.             (str_to_num(octets[3]));
  56.        
  57.         // Ignore private IPv4 address spaces
  58.         if ((address & 0xFF000000) == 0x0A000000 ||    //10.0.0.0/8
  59.         (address & 0xFFF00000) == 0xAC100000 ||       //172.16.0.0/12
  60.         (address & 0xFFFF0000) == 0xC0A80000 ||       //192.168.0.0/16
  61.         (address & 0xFF000000) == 0x7F000000)         //127.0.0.0/8
  62.         {
  63.             return;
  64.         }
  65.     }
  66.  
  67.     new data = nvault_get(g_hVault, netAddress);
  68.  
  69.     if (data) {
  70.         if (data == 1) {
  71.             punish_player(id);
  72.         }
  73.  
  74.         return;
  75.     }
  76.  
  77.     new szFile[PLATFORM_MAX_PATH];
  78.     formatex(szFile, charsmax(szFile), "%s/check_%s.txt", g_szDataDir, netAddress);
  79.  
  80.     if (!file_exists(szFile)) {
  81.         new szRequest[68];
  82.  
  83.         formatex(szRequest, charsmax(szRequest), "https://ip.teoh.io/api/vpn/%s", netAddress);
  84.         grip_request(szRequest, Empty_GripBody, GripRequestTypeGet, "HandleRequest");
  85.     }
  86. }
  87.  
  88. public HandleRequest() {
  89.     new GripResponseState:responseState = grip_get_response_state();
  90.  
  91.     if (responseState == GripResponseStateError) {
  92.         return;
  93.     }
  94.  
  95.     new GripHTTPStatus:status = grip_get_response_status_code();
  96.  
  97.     if (status != GripHTTPStatusOk) {
  98.         return;
  99.     }
  100.  
  101.     new response[512];
  102.     grip_get_response_body_string(response, charsmax(response));
  103.  
  104.     new GripJSONValue:data = grip_json_parse_response_body(response, charsmax(response));
  105.  
  106.     if (data == Invalid_GripJSONValue) {
  107.         return;
  108.     }
  109.  
  110.     new netAddress[MAX_IP_LENGTH];
  111.    
  112.     grip_json_get_string(grip_json_object_get_value(data, "ip"), netAddress, MAX_IP_LENGTH);
  113.     grip_json_get_string(grip_json_object_get_value(data, "vpn_or_proxy"), response, charsmax(response));
  114.  
  115.     if (equal(response, "yes")) {
  116.         nvault_set(g_hVault, netAddress, "1");
  117.         punish_player(find_player("d", netAddress));
  118.     } else {
  119.         nvault_set(g_hVault, netAddress, "2");
  120.     }
  121.        
  122.     grip_destroy_json_value(data);
  123. }
  124.  
  125. punish_player(id) {
  126.     if(!is_user_connected(id)) {
  127.         return;
  128.     }
  129.    
  130.     server_cmd("kick #%d ^"Proxy/VPN not Allowed!^"", get_user_userid(id));
  131. }
So please can you help me to fix this plugin code so to make it works as it should be?
Thanks in advance. :)

User avatar
z0h1r-LK
Mod Developer
Mod Developer
Morocco
Posts: 476
Joined: 5 years ago
Location: The Red City ❤
Contact:

#2

Post by z0h1r-LK » 3 years ago

Good bro
Block vpn and proxy if user has banned from server using IP 👌🏻👌🏻👌🏻

User avatar
sPe3doN
Senior Member
Senior Member
Algeria
Posts: 258
Joined: 7 years ago
Contact:

#3

Post by sPe3doN » 3 years ago

@raheem can you fix this I need to it for my server
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#4

Post by Raheem » 3 years ago

Good idea to put some limitations on cheaters.

For those who does not know how this works, the plugin require a module called: grip. The author build this module for Linux only, you will need to build this module for windows if you need to run this blocker on windows. Don't forget to write grip in modules.ini.

The plugin will kick any player who uses VPN. Also please note that in logs directory, you will find a file named VPN-Detected.log, in this file you can see Name & IP of players who used VPN and got kicked previously.

Download the .SMA/.AMXX + Module: If you need only the code:
    1. #include <amxmodx>
    2. #include <grip>
    3.  
    4. #pragma semicolon 1
    5.  
    6. #define MAX_IP_LENGTH 40
    7.  
    8. public plugin_init()
    9. {
    10.     register_plugin("VPN/Proxy Blocker", "2.1", "juice, voed");
    11. }
    12.  
    13. public client_putinserver(id)
    14. {
    15.     if (is_user_bot(id) || is_user_hltv(id))
    16.         return;
    17.    
    18.     new netAddress[MAX_IP_LENGTH];
    19.     get_user_ip(id, netAddress, charsmax(netAddress), 1);
    20.  
    21.     if (netAddress[0] == 'l')
    22.     {
    23.         return;
    24.     }
    25.     else
    26.     {
    27.         new buf[sizeof netAddress];
    28.  
    29.         copy(buf, charsmax(buf), netAddress);
    30.         replace_all(buf, charsmax(buf), ".", " ");
    31.        
    32.         new octets[4][4];
    33.         parse(buf, octets[0], charsmax(octets[]),
    34.             octets[1], charsmax(octets[]),
    35.             octets[2], charsmax(octets[]),
    36.             octets[3], charsmax(octets[]));
    37.                
    38.         new address = (str_to_num(octets[0]) << 24) |
    39.             (str_to_num(octets[1]) << 16) |
    40.             (str_to_num(octets[2]) << 8) |
    41.             (str_to_num(octets[3]));
    42.        
    43.         // Ignore private IPv4 address spaces
    44.         if ((address & 0xFF000000) == 0x0A000000 ||    //10.0.0.0/8
    45.         (address & 0xFFF00000) == 0xAC100000 ||       //172.16.0.0/12
    46.         (address & 0xFFFF0000) == 0xC0A80000 ||       //192.168.0.0/16
    47.         (address & 0xFF000000) == 0x7F000000)         //127.0.0.0/8
    48.         {
    49.             return;
    50.         }
    51.     }
    52.  
    53.     new szRequest[100];
    54.     formatex(szRequest, charsmax(szRequest), "https://ip.teoh.io/api/vpn/%s", netAddress);
    55.        
    56.     grip_request(szRequest, Empty_GripBody, GripRequestTypeGet, "HandleRequest");
    57. }
    58.  
    59. public HandleRequest()
    60. {
    61.     new GripResponseState:responseState = grip_get_response_state();
    62.  
    63.     if (responseState == GripResponseStateError)
    64.         return;
    65.  
    66.     new GripHTTPStatus:status = grip_get_response_status_code();
    67.  
    68.     if (status != GripHTTPStatusOk)
    69.         return;
    70.  
    71.     new response[512];
    72.     grip_get_response_body_string(response, charsmax(response));
    73.  
    74.     new GripJSONValue:data = grip_json_parse_response_body(response, charsmax(response));
    75.  
    76.     if (data == Invalid_GripJSONValue)
    77.         return;
    78.    
    79.     new netAddress[MAX_IP_LENGTH];
    80.    
    81.     grip_json_get_string(grip_json_object_get_value(data, "ip"), netAddress, MAX_IP_LENGTH);
    82.     grip_json_get_string(grip_json_object_get_value(data, "vpn_or_proxy"), response, charsmax(response));
    83.    
    84.     if (equal(response, "yes"))
    85.         punish_player(find_player("d", netAddress));
    86.        
    87.     grip_destroy_json_value(data);
    88. }
    89.  
    90. punish_player(id)
    91. {
    92.     if(!is_user_connected(id))
    93.         return;
    94.    
    95.     new szName[32], szIP[40];
    96.     get_user_name(id, szName, charsmax(szName));
    97.     get_user_ip(id, szIP, charsmax(szIP), 1);
    98.    
    99.     log_to_file("VPN-Detected.log", "Name: %s - IP: %s", szName, szIP);
    100.     server_cmd("kick #%d ^"Proxy/VPN not Allowed!^"", get_user_userid(id));
    101. }
Topic marked as resolved. (I tested it and it's working, report any issue if any exists)
Also sorry for late response but was busy.
He who fails to plan is planning to fail

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#5

Post by Raheem » 3 years ago

Raheem wrote: 3 years ago Good idea to put some limitations on cheaters.

For those who does not know how this works, the plugin require a module called: grip. The author build this module for Linux only, you will need to build this module for windows if you need to run this blocker on windows. Don't forget to write grip in modules.ini.

The plugin will kick any player who uses VPN. Also please note that in logs directory, you will find a file named VPN-Detected.log, in this file you can see Name & IP of players who used VPN and got kicked previously.

Download the .SMA/.AMXX + Module:
  • Block VPN.zip
If you need only the code:
    1. #include <amxmodx>
    2. #include <grip>
    3.  
    4. #pragma semicolon 1
    5.  
    6. #define MAX_IP_LENGTH 40
    7.  
    8. public plugin_init()
    9. {
    10.     register_plugin("VPN/Proxy Blocker", "2.1", "juice, voed");
    11. }
    12.  
    13. public client_putinserver(id)
    14. {
    15.     if (is_user_bot(id) || is_user_hltv(id))
    16.         return;
    17.    
    18.     new netAddress[MAX_IP_LENGTH];
    19.     get_user_ip(id, netAddress, charsmax(netAddress), 1);
    20.  
    21.     if (netAddress[0] == 'l')
    22.     {
    23.         return;
    24.     }
    25.     else
    26.     {
    27.         new buf[sizeof netAddress];
    28.  
    29.         copy(buf, charsmax(buf), netAddress);
    30.         replace_all(buf, charsmax(buf), ".", " ");
    31.        
    32.         new octets[4][4];
    33.         parse(buf, octets[0], charsmax(octets[]),
    34.             octets[1], charsmax(octets[]),
    35.             octets[2], charsmax(octets[]),
    36.             octets[3], charsmax(octets[]));
    37.                
    38.         new address = (str_to_num(octets[0]) << 24) |
    39.             (str_to_num(octets[1]) << 16) |
    40.             (str_to_num(octets[2]) << 8) |
    41.             (str_to_num(octets[3]));
    42.        
    43.         // Ignore private IPv4 address spaces
    44.         if ((address & 0xFF000000) == 0x0A000000 ||    //10.0.0.0/8
    45.         (address & 0xFFF00000) == 0xAC100000 ||       //172.16.0.0/12
    46.         (address & 0xFFFF0000) == 0xC0A80000 ||       //192.168.0.0/16
    47.         (address & 0xFF000000) == 0x7F000000)         //127.0.0.0/8
    48.         {
    49.             return;
    50.         }
    51.     }
    52.  
    53.     new szRequest[100];
    54.     formatex(szRequest, charsmax(szRequest), "https://ip.teoh.io/api/vpn/%s", netAddress);
    55.        
    56.     grip_request(szRequest, Empty_GripBody, GripRequestTypeGet, "HandleRequest");
    57. }
    58.  
    59. public HandleRequest()
    60. {
    61.     new GripResponseState:responseState = grip_get_response_state();
    62.  
    63.     if (responseState == GripResponseStateError)
    64.         return;
    65.  
    66.     new GripHTTPStatus:status = grip_get_response_status_code();
    67.  
    68.     if (status != GripHTTPStatusOk)
    69.         return;
    70.  
    71.     new response[512];
    72.     grip_get_response_body_string(response, charsmax(response));
    73.  
    74.     new GripJSONValue:data = grip_json_parse_response_body(response, charsmax(response));
    75.  
    76.     if (data == Invalid_GripJSONValue)
    77.         return;
    78.    
    79.     new netAddress[MAX_IP_LENGTH];
    80.    
    81.     grip_json_get_string(grip_json_object_get_value(data, "ip"), netAddress, MAX_IP_LENGTH);
    82.     grip_json_get_string(grip_json_object_get_value(data, "vpn_or_proxy"), response, charsmax(response));
    83.    
    84.     if (equal(response, "yes"))
    85.         punish_player(find_player("d", netAddress));
    86.        
    87.     grip_destroy_json_value(data);
    88. }
    89.  
    90. punish_player(id)
    91. {
    92.     if(!is_user_connected(id))
    93.         return;
    94.    
    95.     new szName[32], szIP[40];
    96.     get_user_name(id, szName, charsmax(szName));
    97.     get_user_ip(id, szIP, charsmax(szIP), 1);
    98.    
    99.     log_to_file("VPN-Detected.log", "Name: %s - IP: %s", szName, szIP);
    100.     server_cmd("kick #%d ^"Proxy/VPN not Allowed!^"", get_user_userid(id));
    101. }
Topic marked as resolved. (I tested it and it's working, report any issue if any exists)
Also sorry for late response but was busy.
⚠️ WARNING: The grip module will crash your server with segmentation fault, so please don't use it!
He who fails to plan is planning to fail

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 9 guests