接入教程
1. 访问URLScan.io官网注册账号并获取API密钥
2. 使用API密钥在请求头中进行身份验证
3. 向扫描端点提交需要分析的URL
4. 等待扫描完成并获取返回的扫描结果
5. 解析JSON格式的报告数据并提取所需信息
使用Python提交URL扫描请求
import requests
import json
url = 'https://api.urlscan.io/v1/scan/'
headers = {
'API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'url': 'https://example.com',
'visibility': 'public'
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
result = response.json()
print(f'扫描提交成功: {result["uuid"]}')
else:
print(f'请求失败: {response.status_code}')
print(response.text)
使用PHP获取扫描结果
<?php
$apiKey = 'YOUR_API_KEY';
$scanId = 'scan_uuid_placeholder';
$url = "https://api.urlscan.io/v1/result/$scanId";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'API-Key: ' . $apiKey
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
$data = json_decode($response, true);
echo '扫描状态: ' . $data['verdicts']['overall']['malicious'] ? '恶意' : '安全';
} else {
echo '获取结果失败,HTTP代码: ' . $httpCode;
}
?>
使用JavaScript搜索历史扫描记录
const apiKey = 'YOUR_API_KEY';
const query = 'example.com';
const url = `https://api.urlscan.io/v1/search/?q=${encodeURIComponent(query)}`;
fetch(url, {
method: 'GET',
headers: {
'API-Key': apiKey
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(`找到 ${data.results.length} 条记录`);
data.results.forEach(result => {
console.log(`URL: ${result.page.url}, 扫描时间: ${result.task.time}`);
});
})
.catch(error => {
console.error('请求失败:', error);
});
常见问题
URLScan.io API是否需要API密钥?
是的,大部分API端点需要有效的API密钥进行身份验证。您可以在URLScan.io官网注册账户后获取API密钥。免费套餐通常提供有限的请求次数。
扫描一个URL需要多长时间?
扫描时间取决于目标网站的复杂性和当前队列负载,通常需要30秒到2分钟。提交扫描请求后会返回一个任务ID,您可以使用该ID轮询获取扫描结果。
API支持哪些扫描可见性设置?
URLScan.io提供三种可见性选项:'public'(公开,结果对所有人可见)、'unlisted'(未列出,仅通过直接链接可访问)和'private'(私有,仅账户持有者可见)。根据您的需求选择合适的设置。
Aitishiku.com