import requests
import tkinter as tk
from tkinter import filedialog, messagebox, scrolledtext, simpledialog
import json
import smtplib
from email.mime.text import MIMEText
from datetime import datetime
API_KEY = 'YOUR_API_KEY'
upload_url = 'https://www.virustotal.com/api/v3/files'
report_url = 'https://www.virustotal.com/api/v3/analyses/'
class VirusTotalApp:
def __init__(self, master):
self.master = master
self.master.title("VirusTotal File Uploader")
self.master.geometry("600x450")
self.upload_button = tk.Button(master, text="Upload Files", command=self.upload_files)
self.upload_button.pack(pady=10)
self.history_button = tk.Button(master, text="Show History", command=self.show_history)
self.history_button.pack(pady=5)
self.export_button = tk.Button(master, text="Export History", command=self.export_history)
self.export_button.pack(pady=5)
self.email_button = tk.Button(master, text="Send Report via Email", command=self.send_report_via_email)
self.email_button.pack(pady=5)
self.result_text = scrolledtext.ScrolledText(master, width=70, height=15)
self.result_text.pack(pady=10)
self.history = []
self.wait_time = 15
def upload_files(self):
file_paths = filedialog.askopenfilenames(title="Select Files to Upload")
if file_paths:
for file_path in file_paths:
analysis_id = self.upload_to_virustotal(file_path)
if analysis_id:
self.result_text.insert(tk.END, f'File uploaded: {file_path}\nAnalysis ID: {analysis_id}\n')
self.master.after(self.wait_time * 1000, lambda id=analysis_id: self.get_report(id))
def upload_to_virustotal(self, file_path):
try:
with open(file_path, 'rb') as file:
response = requests.post(
upload_url,
headers={'x-apikey': API_KEY},
files={'file': file}
)
if response.status_code == 200:
analysis_id = response.json()['data']['id']
self.history.append({
'file_path': file_path,
'analysis_id': analysis_id,
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'status': 'uploaded'
})
return analysis_id
else:
messagebox.showerror("Error", f"Failed to upload file. Status code: {response.status_code}\nError: {response.json()}")
return None
except Exception as e:
messagebox.showerror("Error", f"An error occurred while uploading the file: {e}")
return None
def get_report(self, analysis_id):
try:
response = requests.get(
report_url + analysis_id,
headers={'x-apikey': API_KEY}
)
if response.status_code == 200:
report = response.json()
self.result_text.insert(tk.END, "Report received:\n")
self.result_text.insert(tk.END, json.dumps(report, indent=2) + "\n\n")
messagebox.showinfo("Info", "Report is ready! You can send it via email.")
else:
messagebox.showerror("Error", f"Failed to retrieve report. Status code: {response.status_code}\nError: {response.json()}")
except Exception as e:
messagebox.showerror("Error", f"An error occurred while retrieving the report: {e}")
def show_history(self):
history_window = tk.Toplevel(self.master)
history_window.title("Upload History")
history_window.geometry("500x300")
history_text = scrolledtext.ScrolledText(history_window, width=60, height=15)
history_text.pack(pady=10)
if self.history:
for entry in self.history:
history_text.insert(tk.END, f"File: {entry['file_path']}\nAnalysis ID: {entry['analysis_id']}\nTime: {entry['timestamp']}\nStatus: {entry['status']}\n\n")
else:
history_text.insert(tk.END, "No upload history found.\n")
def export_history(self):
if not self.history:
messagebox.showwarning("Warning", "No history to export.")
return
export_path = filedialog.asksaveasfilename(defaultextension=".json", title="Save History as JSON")
if export_path:
with open(export_path, 'w') as f:
json.dump(self.history, f, indent=2)
messagebox.showinfo("Info", f"History exported successfully to {export_path}!")
def send_report_via_email(self):
email_address = simpledialog.askstring("Input", "Enter your email address:")
if not email_address:
messagebox.showwarning("Warning", "You must enter an email address.")
return
if not self.history:
messagebox.showwarning("Warning", "No reports to send.")
return
report_content = ""
for entry in self.history:
report_content += f"File: {entry['file_path']}\nAnalysis ID: {entry['analysis_id']}\nTime: {entry['timestamp']}\nStatus: {entry['status']}\n\n"
report_content += "End of Report\n"
self.send_email(email_address, "VirusTotal Report", report_content)
def send_email(self, to_email, subject, body):
try:
smtp_server = 'smtp.gmail.com'
smtp_port = 587
sender_email = 'YOUR_EMAIL@gmail.com'
sender_password = 'YOUR_EMAIL_PASSWORD'
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(sender_email, sender_password)
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender_email
msg['To'] = to_email
server.sendmail(sender_email, to_email, msg.as_string())
messagebox.showinfo("Success", "Report sent successfully via email!")
except Exception as e:
messagebox.showerror("Error", f"Failed to send email: {e}")
if __name__ == "__main__":
root = tk.Tk()
app = VirusTotalApp(root)
root.mainloop()