New Extension for Plesk. Antivirus Protection to enhance your server security. Why choose Flex Antivirus?

API — Web Programming

How to block an IP from a country - Russia

Integrates IP blocking functionality directly into your web application if it belongs to a specific country. Compatible with classic ASP and PHP via the extension's COM object.

Classic ASP PHP XML / JSON

Function BlockIp(IP,Rulename)

From your web page — in your index.asp, index.php, or any section of your application — you can call this function to block an IP address through Firewall Manager. It requires valid credentials for a domain in Plesk.

1 Required parameters


Parameter Type Required Description
Username String Required Plesk domain user with access to the extension.
Password String Required Password for the Plesk domain user.
FormatOutput String Optional Response format: xml (default) or json.
IP String Required IPv4 or IPv6 address to be blocked.
Rulename String Optional Name of the rule where the IP address should be assigned. Do not use by default.
json/xml return values
result
(true or false) Status of the block request.
app
Site where it was blocked: Windows, MailEnable, Cloudflare
desc
If the result is negative, it will show information about the reason.

Important: Use this function on pages protected with your own authentication. Exposing the call without protection allows any user to block arbitrary IPs.

2 Classic ASP example


Instantiate the FlexFirewallManager.Admin COM object, set the credentials, and call UnlockIP(). The response is parsed as XML.

' Create COM object instance Set App = CreateObject("FlexFirewallManager.Admin") App.FormatOutput = "xml" App.Username = "Plesk Domain User" App.Password = "Plesk Domain Password" ' IP to block Dim strCountry : strIP = Request.ServerVariables("HTTP_X_FIREWALL_COUNTRY") Dim strIP : strIP = Request.ServerVariables("HTTP_X_FIREWALL_IP") If strIP = "" Then strIP = Request.ServerVariables("REMOTE_ADDR") ' Method 1 If strCountry = "CN" Then App.BlockIp(strIP) End If ' Method 2 Dim returnstring : returnstring = App.InfoIP(strIP) ' Parse XML response Set objxml = CreateObject("Msxml2.DOMDocument") objxml.LoadXml(returnstring) If LCase(objxml.SelectSingleNode("/output/result").text) = "true" Then If UCase(objxml.SelectSingleNode("/output/countrycode").text) = "RU" Then App.BlockIp(strIP) End If End If

You can use FormatOutput = "json" if you prefer to parse the response with JSON.parse instead of XML. JSON format is recommended for modern applications.

3 PHP example


In PHP, instantiate the COM object with new COM(). Use json format to parse the response directly with json_decode().

// Create COM object instance $app = new COM("FlexFirewallManager.Admin"); $app->FormatOutput = "json"; $app->Username = "Plesk Domain User"; $app->Password = "Plesk Domain Password"; // IP to block $strCountry = $_SERVER['HTTP_X_FIREWALL_COUNTRY'];; $strIP = $_SERVER['HTTP_X_FIREWALL_IP'];; if ($strIP=="") { $strIP = $_SERVER['REMOTE_ADDR'];; } // Method 1 if ($strCountry == "CN") { $app->BlockIp($strIP); } // Method 2 $returnstring = $app->InfoIP($strIP); // Parse JSON response $appjson = json_decode($returnstring); if ($appjson->result) { if ($appjson->countrycode == "RU") { $app->BlockIp($strIP); } }

Tip: You can combine this function with an internal administration form so your users can self-manage blocking their own IP without needing access to the Plesk panel.

4 Implementation notes


Keep the following in mind when integrating this function into your application:

Prior authentication Always protect the page that calls BlockIp() with an authenticated user session.
Windows Server only The FlexFirewallManager.Admin COM object requires Windows Server with the extension installed.
Secure credentials Never include the username and password in publicly accessible source code. Use environment variables or external configuration files.
Cloudflare synchronization If you have Cloudflare integration enabled, blocking will only be applied to Cloudflare's rules.