-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
115 lines (96 loc) · 3.6 KB
/
Copy pathsetup.py
File metadata and controls
115 lines (96 loc) · 3.6 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
"""
Network Packet Sniffer and Analyzer
Setup and Installation Script
This script helps set up the environment and dependencies for the packet analyzer.
"""
import subprocess
import sys
import os
from pathlib import Path
def check_python_version():
"""Check if Python version is 3.7 or higher"""
if sys.version_info < (3, 7):
print("❌ Python 3.7 or higher is required")
print(f"Current version: {sys.version}")
return False
print(f"✅ Python version: {sys.version}")
return True
def install_requirements():
"""Install required Python packages"""
print("\n📦 Installing Python dependencies...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("✅ All dependencies installed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to install dependencies: {e}")
return False
def check_wireshark():
"""Check if Wireshark/tshark is installed"""
print("\n🔍 Checking for Wireshark installation...")
# Common tshark paths
possible_paths = [
"tshark", # In PATH
"C:\\Program Files\\Wireshark\\tshark.exe",
"C:\\Program Files (x86)\\Wireshark\\tshark.exe",
"/usr/bin/tshark", # Linux
"/usr/local/bin/tshark", # macOS
]
for path in possible_paths:
try:
result = subprocess.run([path, "--version"],
capture_output=True, text=True, timeout=10)
if result.returncode == 0:
print(f"✅ Found tshark at: {path}")
return path
except (subprocess.TimeoutExpired, FileNotFoundError, subprocess.SubprocessError):
continue
print("❌ Wireshark/tshark not found")
print("Please install Wireshark from: https://www.wireshark.org/")
return None
def download_nltk_data():
"""Download required NLTK data"""
print("\n📚 Setting up NLTK data...")
try:
import nltk
nltk.download('punkt', quiet=True)
print("✅ NLTK data downloaded successfully")
return True
except Exception as e:
print(f"⚠️ Could not download NLTK data: {e}")
print("You may need to run: python -c \"import nltk; nltk.download('punkt')\"")
return False
def create_directories():
"""Create necessary directories"""
print("\n📁 Creating project directories...")
directories = ['captures', 'logs', 'screenshots']
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print(f"✅ Created directory: {directory}")
def main():
"""Main setup function"""
print("🚀 Network Packet Analyzer Setup")
print("=" * 40)
# Check Python version
if not check_python_version():
sys.exit(1)
# Install requirements
if not install_requirements():
print("⚠️ Some dependencies failed to install. You may need to install them manually.")
# Check Wireshark
tshark_path = check_wireshark()
if tshark_path:
print(f"\n📝 Update the tshark path in packet_sniffer_gui.py:")
print(f" pyshark.tshark.tshark_path = r\"{tshark_path}\"")
# Download NLTK data
download_nltk_data()
# Create directories
create_directories()
print("\n" + "=" * 40)
print("🎉 Setup completed!")
print("\nTo run the application:")
print(" python packet_sniffer_gui.py")
print("\n⚠️ Note: You may need administrator privileges for packet capture")
if __name__ == "__main__":
main()