Usage example for the read_cphulk_records API script to obtain IPs blacklisted in cPhulk Brute Force Protection >> Blacklist Management area:
Code:
#!/bin/env perl
use strict;
use LWP::UserAgent;
use LWP::Protocol::https;
my $hash = "replace-with-/root/.accesshash-contents";
$hash =~ s/\n//g;
my $auth = "WHM root:" . $hash;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
my $ua = LWP::UserAgent->new;
my $request =
HTTP::Request->new( GET => "https://127.0.0.1:2087/json-api/read_cphulk_records?api.version=1&list_name=black&ips_in_list" );
$request->header( Authorization => $auth );
my $response = $ua->request($request);
print $response->content;
For the script, install the following Perl modules and make it executable:
Code:
/scripts/perlinstaller --force IO::Socket::SSL
/scripts/perlinstaller --force Net::SSLeay
chmod +x /pathtoscript
Then run the script:
Code:
/pathtoscript | python -mjson.tool
Example return:
[email protected] [~]# /root/blacklist.pl | python -mjson.tool | grep -v '\{\|\}'
"1.2.3.4": null
"list_name": "black",
"requester_ip": "127.0.0.1"
"command": "read_cphulk_records",
"reason": "OK",
"result": 1,
"version": 1