Tesi / script.js
Abdfah's picture
Create script.js
c202344 verified
Raw History Blame Contribute Delete
4.03 kB
// 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;
}
});