File size: 4,034 Bytes
c202344 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | // Your VirusTotal API key
const API_KEY = '070e7e19f80dfa11c0e4d34c7a10d8dd68428389b25a05db24bd4519e775c36c';
const headers = { 'x-apikey': API_KEY };
// File Upload & Analysis
const uploadBtn = document.getElementById('uploadBtn');
uploadBtn.addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) return alert('Please select a file');
const form = new FormData();
form.append('file', fileInput.files[0]);
try {
const { data } = await axios.post('https://www.virustotal.com/api/v3/files', form, {
headers: { ...form.getHeaders(), ...headers }
});
document.getElementById('fileResult').textContent = JSON.stringify(data, null, 2);
} catch (err) {
document.getElementById('fileResult').textContent = err;
}
});
// URL Analysis
document.getElementById('submitUrlBtn').addEventListener('click', async () => {
const url = document.getElementById('urlInput').value;
try {
const { data } = await axios.post('https://www.virustotal.com/api/v3/urls',
`url=${encodeURIComponent(url)}`, {
headers: { ...headers, 'Content-Type': 'application/x-www-form-urlencoded' }
}
);
document.getElementById('urlResult').textContent = JSON.stringify(data, null, 2);
} catch (err) {
document.getElementById('urlResult').textContent = err;
}
});
document.getElementById('getUrlReportBtn').addEventListener('click', async () => {
const urlId = document.getElementById('urlInput').value;
try {
const { data } = await axios.get(`https://www.virustotal.com/api/v3/urls/${urlId}`, { headers });
document.getElementById('urlResult').textContent = JSON.stringify(data, null, 2);
} catch (err) {
document.getElementById('urlResult').textContent = err;
}
});
// IP / Domain Report
document.getElementById('getIpBtn').addEventListener('click', async () => {
const ip = document.getElementById('ipInput').value;
try {
const { data } = await axios.get(`https://www.virustotal.com/api/v3/ip_addresses/${ip}`, { headers });
document.getElementById('ipDomainResult').textContent = JSON.stringify(data, null, 2);
} catch (err) {
document.getElementById('ipDomainResult').textContent = err;
}
});
document.getElementById('getDomainBtn').addEventListener('click', async () => {
const domain = document.getElementById('ipInput').value;
try {
const { data } = await axios.get(`https://www.virustotal.com/api/v3/domains/${domain}`, { headers });
document.getElementById('ipDomainResult').textContent = JSON.stringify(data, null, 2);
} catch (err) {
document.getElementById('ipDomainResult').textContent = err;
}
});
// Comments & Votes
const resourceIdInput = document.getElementById('resourceIdInput');
document.getElementById('commentBtn').addEventListener('click', async () => {
const id = resourceIdInput.value;
const text = document.getElementById('commentText').value;
const body = { data: { type: 'comment', attributes: { text } } };
try {
const { data } = await axios.post(
`https://www.virustotal.com/api/v3/files/${id}/comments`,
body,
{ headers: { ...headers, 'Content-Type': 'application/json' } }
);
document.getElementById('commentVoteResult').textContent = JSON.stringify(data, null, 2);
} catch (err) {
document.getElementById('commentVoteResult').textContent = err;
}
});
document.getElementById('voteBtn').addEventListener('click', async () => {
const id = resourceIdInput.value;
const verdict = document.getElementById('voteSelect').value;
const body = { data: { type: 'vote', attributes: { verdict } } };
try {
const { data } = await axios.post(
`https://www.virustotal.com/api/v3/files/${id}/votes`,
body,
{ headers: { ...headers, 'Content-Type': 'application/json' } }
);
document.getElementById('commentVoteResult').textContent = JSON.stringify(data, null, 2);
} catch (err) {
document.getElementById('commentVoteResult').textContent = err;
}
}); |