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
)
*/
?>
这要怎么用啊,求大神解答!!!
大体说下思路,这个api是用来批量执行查询的,用的是php语言,php语言需要先安装php环境,如果在一个全新的环境下,
参照这个网址
https://jingyan.baidu.com/article/a681b0de3fbe7f3b18434684.html
把环境搭建起来。然后把它给的2个文件运行起来就能看到结果
class_urlvoidapi.php:是把查询做成了1个服务器,你按规则拼出查询url就能进行查询,这样的话可以用其他语言或脚本调用
example.php:是php语言的调用例子,里面写了一些例程检测地址,你的apikey是放在
$URLVoidAPI = new URLVoidAPI( 'YOUR_API_KEY_HERE', 'api1000' );
这句话的YOUR_API_KEY_HERE这里,把它删了,换成你的api
$array = $URLVoidAPI->scan_host( "quintadabigorna.com" );
双引号里面的地址换成你需要检测到网站,每个都是一块,按格式仿照写就行
最后的运行结果是这样的
Example data present in the $array
在这之后的是结果
你可以解析出来结果,从而完成批量处理
文件1(class_urlvoidapi.php_)为虚拟访问请求,如果你不是PHP的网页系统,就将他改装一下就好了,
如果你是在pc系统做检测使用,可以直接安装一个php的小型服务器,楼上的是一个不错的方法,安装后操作如下:
进入htdocs文件夹,将两个文件复制进去,然后用记事本打开example.php,全选删除(毕竟你看不懂),输入一下代码:
require_once 'class_urlvoidapi.php';//引用文件1
$URLVoidAPI = new URLVoidAPI( '9ca03b705eb8e07cfac7dc8518d661950fd4a27', 'api1000' );
$arr1 = array('你的域名1','你的域名1','你的域名1','你的域名1');//有多少个域名写多少个,不要以“,”结尾
$array = array();
foreach($arr1 as $host){
$array = $URLVoidAPI->scan_host( "$host" );
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 />';
}
保存后,用浏览器访问http://localhost/example.php即可