Eumenides-Z 2018-05-14 05:10 采纳率: 100%
浏览 1078
已结题

如何调用一个API,关于urlvoid的

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
)
*/

?>

这要怎么用啊,求大神解答!!!

  • 写回答

2条回答 默认 最新

  • zheshiweihe 2018-05-14 05:45
    关注

    大体说下思路,这个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
    在这之后的是结果
    你可以解析出来结果,从而完成批量处理

    评论

报告相同问题?

悬赏问题

  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd