-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
98 lines (82 loc) · 2.81 KB
/
run.py
File metadata and controls
98 lines (82 loc) · 2.81 KB
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
#!/usr/bin/env python3
"""
Run script for Network Traffic Analyzer
"""
import os
import sys
import subprocess
import time
import webbrowser
import platform
def check_ollama():
"""Check if Ollama is installed and running"""
print("Checking if Ollama is installed and running...")
try:
# Try to connect to Ollama API
import requests
response = requests.get("http://localhost:11434/api/tags")
if response.status_code == 200:
print("✅ Ollama is running")
return True
else:
print("❌ Ollama is installed but not running")
return False
except Exception:
print("❌ Ollama API not available. Make sure Ollama is installed and running")
print(" Download Ollama from: https://ollama.ai")
return False
def check_dependencies():
"""Check if all required dependencies are installed"""
print("Checking dependencies...")
try:
# Try to import key dependencies
import flask
import scapy
import requests
print("✅ Python dependencies are installed")
return True
except ImportError as e:
print(f"❌ Missing dependency: {e}")
print("Installing dependencies...")
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
return False
def main():
"""Main function to run the application"""
print("=" * 60)
print("Network Traffic Analyzer - Startup")
print("=" * 60)
# Check dependencies
if not check_dependencies():
print("Dependencies installed. Please run this script again.")
return
# Check Ollama
check_ollama()
# Create logs directory if it doesn't exist
os.makedirs("logs", exist_ok=True)
os.makedirs("cache", exist_ok=True)
# Run the application
print("\nStarting Network Traffic Analyzer...")
# Determine how to run the application based on the platform
if platform.system() == "Windows":
# On Windows, use pythonw to avoid blocking the console
process = subprocess.Popen([sys.executable, "src/app.py"])
else:
# On Linux/Mac, use regular python
process = subprocess.Popen([sys.executable, "src/app.py"])
# Wait a moment for the server to start
time.sleep(2)
# Open web browser
print("Opening web interface in your browser...")
webbrowser.open("http://localhost:5000")
print("\nApplication is running!")
print("Press Ctrl+C to stop the application")
try:
# Keep the script running until user interrupts
process.wait()
except KeyboardInterrupt:
print("\nStopping application...")
process.terminate()
process.wait()
print("Application stopped")
if __name__ == "__main__":
main()