Country IP Blocks REST API



  • Imagine no longer having to keep a database of country specific networks.

    Country IP Blocks is preparing to release a beta REST API. The initial release will be for PHP SSI websites with the anticipation of creating a module specifically for pfsense in the near future.

    This API will allow users to remote query Country IP Blocks and receive the Country Code of web visitors (future versions will also respond to firewall requests). Users will no longer have to keep a database updated with Country Network changes.

    Initial testing will require the following:

    1.) Beta Testers must have a web server with PHP 5.2+ with cURL enabled (if cURL will not enabled step 2 will be required).
    2.) Server must be able to process simplexml.
    3.) Beta Testers must enroll in the beta testing program. With this data we will create user accounts.
    4.) Report any issues to Country IP Blocks.
    5.) Supply Country IP Blocks with feedback.

    The API is designed to remote query one of the Country IP Blocks database servers. Queries will include the following data, visitor IP, CIPB_LICENSE_KEY, CIPB_USER_ID, CIPB_CLIENT_KEY, web server IP.

    Query response will include two character ISO Country Code.

    To See if your web server qualifies for the initial beta testing, you can try one or both of the following scripts. Each script will send data related to the following parameters: Visitor IP, Server IP, License Key, Client Key and User ID, The query response will include data in a XML format from which PHP variables will be processed and displayed. If the variables are displayed when you run the script, your server may be considered for our beta testing program.

    cURL Version:

    	function respond_to_cipb_data($country_code) {
    		// custom function to respond to data
    	}
    
    	$server = $_SERVER['SERVER_ADDR'];
    	$ip = $_SERVER['REMOTE_ADDR'];	
    	$license = 'CIPB_LICENSE_KEY';
    	$client_key = 'CIPB_CLIENT_KEY';
    	$user_id = 'CIPB_USER_ID';
    	if (!isset($params['license'])) $params['license'] = "$license";
    	if (!isset($params['ip'])) $params['ip'] = "$ip";
    	if (!isset($params['client_key'])) $params['client_key'] = "$client_key";
    	if (!isset($params['user_id'])) $params['user_id'] = "$user_id";
    	if (!isset($params['server'])) $params['server'] = "$server";
    
    	$request_url = 'https://www.countryipblocks.net/t/?' . http_build_query($params);
    	 function get_url($request_url) {
    	  $ch = curl_init();
    	  curl_setopt($ch, CURLOPT_URL, $request_url);
    	  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    	  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	  $response = curl_exec($ch);
    	  curl_close($ch);
    
    	  return $response;
    	}
    
    	$response = get_url($request_url);
    
    	$xml = simplexml_load_string($response);
    	$country_code = $xml->country;
    	$ip_returned = $xml->ip;
    	$license_code = $xml->license;
    	$user_id_returned = $xml->user_id;
    	$client_key_returned = $xml->client_key;
    	$server_returned = $xml->server;
    
    	echo "IP: " . $ip_returned . "
    Country Code: " . $country_code . "
    License Code: " . $license_code . "
    User ID: " . $user_id_returned . "
    Client Key: " . $client_key_returned . "
    Server Address:"  . $server_returned;
    	respond_to_cipb_data($country_code);
    ?>
    

    Simplexml without cURL:

    
    	$server = $_SERVER['SERVER_ADDR'];
    	$ip = $_SERVER['REMOTE_ADDR'];
    	$license = 'CIPB_LICENSE_KEY';
    	$client_key = 'CIPB_CLIENT_KEY';
    	$user_id = 'CIPB_USER_ID';
    	if (!isset($params['license'])) $params['license'] = "$license";
    	if (!isset($params['ip'])) $params['ip'] = "$ip";
    	if (!isset($params['client_key'])) $params['client_key'] = "$client_key";
    	if (!isset($params['user_id'])) $params['user_id'] = "$user_id";
    	if (!isset($params['server'])) $params['server'] = "$server";
    
    	$request_url = 'https://www.countryipblocks.net/t/?' . http_build_query($params);
    
    	$xml = simplexml_load_file($request_url);
    	$country_code = $xml->country;
    	$ip_returned = $xml->ip;
    	$license_code = $xml->license;
    	$user_id_returned = $xml->user_id;
    	$client_key_returned = $xml->client_key;
    	$server_returned = $xml->server;
    
    	echo "IP: " . $ip_returned . "
    Country Code: " . $country_code . "
    License Code: " . $license_code . "
    User ID: " . $user_id_returned . "
    Client Key: " . $client_key_returned . "
    Server Address:"  . $server_returned;
    
    ?>
    

    If you have any questions please post them here or drop us a line at connecting@countryipblocks.net with BETA TESTER in the subject line. We will have an enrollment form available on the website in a few days.

    Country IP Blocks LLC reserves the right to accept or reject any applicant to our Beta Testing program.


Locked