www.urlvoid.com 是一个检测URL是否恶意的网站,但在网站上一次只能查询一个URL,我有很多URL要检测,所以要调用urlvoid API来批量处理。
我注册了个账号,得到了API key ,但我不会用啊。
它还给的有PHP格式的两个文件:
文件class_urlvoidapi.php:
<?php
/*
* Query URLVoid database through the API
* http://www.urlvoid.com/
*
*/
class URLVoidAPI
{
private $_api;
private $_plan;
public $_output;
public $_error;
public function __construct( $api, $plan )
{
$this->_api = $api;
$this->_plan = $plan;
}
/*
* Set key for the API call
*/
public function set_api( $api )
{
$this->_api = $api;
}
/*
* Set plan identifier for the API call
*/
public function set_plan( $plan )
{
$this->_plan = $plan;
}
/*
* Call the API
*/
public function query_urlvoid_api( $website )
{
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://api.urlvoid.com/".$this->_plan."/".$this->_api."/host/".$website."/" );
curl_setopt ($curl, CURLOPT_USERAGENT, "API");
curl_setopt ($curl, CURLOPT_TIMEOUT, 30);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec( $curl );
curl_close( $curl );
return $result;
}
/*
* Convert array of engines to string
*/
public function show_engines_array_as_string( $engines, $last_char = ", " )
{
if ( is_array($engines) )
{
foreach( $engines as $item ) $str .= trim($item).$last_char;
return rtrim( $str, $last_char );
}
else
{
return $engines;
}
}
public function scan_host( $host )
{
$output = $this->query_urlvoid_api( $host );
$this->_output = $output;
$this->_error = ( preg_match( "/<error>(.*)<\/error>/is", $output, $parts ) ) ? $parts[1] : '';
return json_decode( json_encode( simplexml_load_string( $output, 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING ) ), true );
}
}
?>
文件example.php:
<?php
/*
* Example usage of URLVoid API Class
*
*/
require_once 'class_urlvoidapi.php';
$URLVoidAPI = new URLVoidAPI( 'YOUR_API_KEY_HERE', 'api1000' );
$array = array();
$array = $URLVoidAPI->scan_host( "quintadabigorna.com" );
echo 'Host: <b>quintadabigorna.com</b><br />';
echo 'Detections: '. ( ( $array['detections']['count'] ) ? '<font color="red">'.intval( $array['detections']['count'] ).'</font>' : '0' ).'<br />';
echo 'Engines: '. ( ( $array['detections']['count'] ) ? htmlspecialchars( $URLVoidAPI->show_engines_array_as_string( $array['detections']['engines']['engine'] ) ) : '-' ).'<br />';
echo 'Error: '.( ( $array['error'] ) ? htmlspecialchars( $array['error'] ) : '-' ).'<br /><br />';
$array = $URLVoidAPI->scan_host( "testtralala.xorg.pl" );
echo 'Host: <b>testtralala.xorg.pl</b><br />';
echo 'Detections: '. ( ( $array['detections']['count'] ) ? '<font color="red">'.intval( $array['detections']['count'] ).'</font>' : '0' ).'<br />';
echo 'Engines: '. ( ( $array['detections']['count'] ) ? htmlspecialchars( $URLVoidAPI->show_engines_array_as_string( $array['detections']['engines']['engine'] ) ) : '-' ).'<br />';
echo 'Error: '.( ( $array['error'] ) ? htmlspecialchars( $array['error'] ) : '-' ).'<br /><br />';
$array = $URLVoidAPI->scan_host( "yahoo.com" );
echo 'Host: <b>yahoo.com</b><br />';
echo 'Detections: '. ( ( $array['detections']['count'] ) ? '<font color="red">'.intval( $array['detections']['count'] ).'</font>' : '0' ).'<br />';
echo 'Engines: '. ( ( $array['detections']['count'] ) ? htmlspecialchars( $URLVoidAPI->show_engines_array_as_string( $array['detections']['engines']['engine'] ) ) : '-' ).'<br />';
echo 'Error: '.( ( $array['error'] ) ? htmlspecialchars( $array['error'] ) : '-' ).'<br /><br />';
$array = $URLVoidAPI->scan_host( "youtube.com" );
echo 'Host: <b>youtube.com</b><br />';
echo 'Detections: '. ( ( $array['detections']['count'] ) ? '<font color="red">'.intval( $array['detections']['count'] ).'</font>' : '0' ).'<br />';
echo 'Engines: '. ( ( $array['detections']['count'] ) ? htmlspecialchars( $URLVoidAPI->show_engines_array_as_string( $array['detections']['engines']['engine'] ) ) : '-' ).'<br />';
echo 'Error: '.( ( $array['error'] ) ? htmlspecialchars( $array['error'] ) : '-' ).'<br /><br />';
$array = $URLVoidAPI->scan_host( "bing.com" );
echo 'Host: <b>bing.com</b><br />';
echo 'Detections: '. ( ( $array['detections']['count'] ) ? '<font color="red">'.intval( $array['detections']['count'] ).'</font>' : '0' ).'<br />';
echo 'Engines: '. ( ( $array['detections']['count'] ) ? htmlspecialchars( $URLVoidAPI->show_engines_array_as_string( $array['detections']['engines']['engine'] ) ) : '-' ).'<br />';
echo 'Error: '.( ( $array['error'] ) ? htmlspecialchars( $array['error'] ) : '-' ).'<br /><br />';
/*
* Example data present in the $array
*
*/
/*
Array
(
[details] => Array
(
[host] => quintadabigorna.com
[updated] => 1400428670
[http_response_code] => 200
[domain_age] => 1234933200
[google_page_rank] => 0
[alexa_rank] => 0
[connect_time] => 0.052696
[header_size] => 242
[download_size] => 12789
[speed_download] => 149174
[external_url_redirect] => -
[ip] => Array
(
[addr] => 217.76.130.26
[hostname] => llgb376.servidoresdns.net
[asn] => 20718
[asname] => arsys.es
[country_code] => ES
[country_name] => Spain
[region_name] => -
[city_name] => -
[continent_code] => EU
[continent_name] => Europe
[latitude] => 40
[longitude] => -4
)
)
[detections] => Array
(
[engines] => Array
(
[engine] => Array
(
[0] => MyWOT
[1] => SCUMWARE
[2] => SURBL
[3] => URLVir
[4] => BitDefender
[5] => z_protect
)
)
[count] => 6
)
[page_load] => 0.00
)
*/
?>
这要怎么用啊,求大神解答!!!