API BlockIp::add_ip question

swbrains

Well-Known Member
Sep 13, 2006
202
27
178
The API documentation for BlockIp::add_ip says "This function blocks IP addresses from accessing a cPanel account's domains." Does this mean it blocks the specified IP from ALL hosted account domains under the same cPanel installation (the entire server) like the CSF Firewall Deny IP interface in WHM, or is this somehow blocking the IP from accessing only the domains on one specific hosted user account?

Thanks!
 

cPanelLauren

Technical Support Community Manager
Staff member
Nov 14, 2017
13,271
1,243
313
Houston
HI @swbrains

It will add an .htaccess entry in the domain's .htaccess, just as would happen if you were to block an IP from the UI. This blocks it from accessing that account's domain's only.

The resulting .htaccess entry if using their example would be the following:
Code:
deny from 192.0.2.0
I also found that a typo in the function will cause it to fail and opened a case for this. The function should be BlockIP not BlockIp
 

swbrains

Well-Known Member
Sep 13, 2006
202
27
178
Thanks. Is there any API function analogous to the Deny IP function in the firewall when you log into WHM?
 

cPanelLauren

Technical Support Community Manager
Staff member
Nov 14, 2017
13,271
1,243
313
Houston
Hi @swbrains

Sort of, there is a way to block IP's via API for the whole server (WHM) but it's not going to utilize the firewall nor will it utilize an .htaccess block. The WHMAPI1 functions associated with cPHulk would do this for you WHM API 1 Sections - cPHulk - Developer Documentation - cPanel Documentation

If you're using CSF and you wanted to block an IP address, while they don't have an API that I'm aware of the command is simply:

Code:
csf -d <ipaddress>