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 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题