-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskAutomation.py
183 lines (140 loc) · 5.69 KB
/
TaskAutomation.py
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import threading
import time
from Discover import Discover
class TaskAutomation:
def __init__(self):
self.tasks = []
self.mode = 'sequential'
self.live_monitor_mode = False
self.modes = {
'sequential': self._sequential_mode,
'timed': self._timed_mode,
'safe': self._safe_mode,
'hardcore': self._hardcore_mode,
'focus': self._focus_mode,
'live_monitor': self._live_monitor_mode,
'smart': self._smart_mode,
}
self.PrivateScanner = Discover()
def set_mode(self, mode):
valid_modes = list(self.modes.keys())
if mode in valid_modes:
self.mode = mode
else:
raise ValueError(f"Invalid mode. Choose from {', '.join(valid_modes)}")
def create_task(self, task_func, *args, **kwargs):
task = threading.Thread(target=task_func, args=args, kwargs=kwargs)
self.tasks.append(task)
def run_tasks(self, interval=0):
if self.mode in self.modes:
if self.mode in ['timed', 'verbose']: # Modes that require an interval
self.modes[self.mode](interval)
else:
self.modes[self.mode]()
else:
raise ValueError(f"Mode {self.mode} not implemented.")
def _sequential_mode(self):
for task in self.tasks:
try:
task.start()
task.join()
except Exception as e:
print(f"[!] Error in task {task.name}: {e}")
def _timed_mode(self, interval):
for task in self.tasks:
try:
task.start()
task.join()
time.sleep(interval)
except Exception as e:
print(f"[!] Error in task {task.name}: {e}")
def _safe_mode(self, time_sleep=3):
for task in self.tasks:
try:
print(f"Safe mode: Logging task {task.name}")
time.sleep(time_sleep)
task.start()
task.join()
except Exception as e:
print(f"[!] Error in task {task.name}: {e}")
def _hardcore_mode(self):
for task in self.tasks:
attempts = 0
while attempts < 3:
try:
task.start()
task.join()
print(f"Hardcore mode: Task {task.name} completed")
break
except Exception as e:
attempts += 1
print(f"Hardcore mode: Task {task.name} failed, attempt {attempts}, error: {e}")
time.sleep(2)
if attempts == 3:
print(f"Hardcore mode: Task {task.name} failed after 3 attempts")
def _focus_mode(self):
for task in self.tasks:
try:
print(f"Focus mode: Starting task {task.name}")
task.start()
task.join()
print(f"Focus mode: Completed task {task.name}")
time.sleep(5)
except Exception as e:
print(f"[!] Error in task {task.name}: {e}")
def _live_monitor_mode(self):
self.live_monitor_mode = True
def monitor():
while self.live_monitor_mode:
remaining_tasks = len([task for task in self.tasks if task.is_alive()])
print(f"Live monitor mode: {remaining_tasks} tasks remaining")
if remaining_tasks == 0:
break
time.sleep(2)
monitor_thread = threading.Thread(target=monitor)
monitor_thread.start()
for task in self.tasks:
try:
task.start()
except Exception as e:
print(f"[!] Error starting task {task.name}: {e}")
for task in self.tasks:
try:
task.join()
except Exception as e:
print(f"[!] Error joining task {task.name}: {e}")
self.live_monitor_mode = False
monitor_thread.join()
def _smart_mode(self, delay=5):
"""
Smart mode: Changes MAC addresses, runs tasks with random delays, and runs tasks sequentially.
Ensures each task is completely finished before launching another.
"""
print("Smart mode: Changing MAC addresses, running tasks with random delays, and running tasks sequentially.")
self.PrivateScanner.GetNetworkData(PrintDetails=False)
for i, task in enumerate(self.tasks):
try:
self.PrivateScanner.change_mac(RandomMAC=True)
time.sleep(delay)
print(f"Starting task {i + 1}/{len(self.tasks)}")
task.start()
task.join() # Ensure the task is finished
print(f"Task {i + 1} completed")
except Exception as e:
print(f"[!] Error in task {i + 1}: {e}")
finally:
if task.is_alive():
try:
task.terminate()
task.join() # Ensure termination is complete
print(f"Task {i + 1} was forcefully terminated")
except Exception as e:
print(f"[!] Error terminating task {i + 1}: {e}")
time.sleep(delay)
try:
self.PrivateScanner.change_mac(Reverse_Mode=True)
except Exception as e:
print(f"[!] Error reverting MAC address: {e}")
time.sleep(delay)
if __name__ == "__main__":
pass