-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetNinja-Toolkit.py
More file actions
571 lines (533 loc) · 21.4 KB
/
NetNinja-Toolkit.py
File metadata and controls
571 lines (533 loc) · 21.4 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
import os
import sys
import ctypes
import subprocess
import shutil
import time
def is_admin():
"""
Check if the script is running with administrator privileges.
"""
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def relaunch_as_admin():
"""
Relaunch the current script with administrator privileges using UAC prompt.
"""
params = ' '.join([f'"{arg}"' for arg in sys.argv])
ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable, params, None, 1
)
def clear_screen():
"""
Clear the console screen (Windows).
"""
os.system('cls')
def show_banner():
"""
Display a simple ASCII banner with the text 'arshiakia'.
"""
text = "arshiakia"
border = "+" + "-" * (len(text) + 4) + "+"
print(border)
print(f"| {text} |")
print(border)
def clear_dns():
"""
Reset DNS settings on all active network adapters to DHCP (automatic),
without loading any PowerShell profiles and bypassing execution policy.
"""
print("[*] Resetting DNS servers to automatic (DHCP) on all active adapters...")
ps_command = (
"Get-NetAdapter | Where-Object {$_.Status -eq 'Up'} | "
"ForEach-Object { Set-DnsClientServerAddress -InterfaceIndex $_.InterfaceIndex -ResetServerAddresses }"
)
subprocess.run([
"powershell",
"-NoProfile",
"-ExecutionPolicy", "Bypass",
"-Command", ps_command
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print("[+] DNS reset complete.")
input("\nPress Enter to continue...")
def clear_proxy():
"""
Remove any system proxy settings (WinHTTP and Internet Settings in registry).
"""
print("[*] Clearing system proxy settings...")
# Reset WinHTTP proxy
subprocess.run(["netsh", "winhttp", "reset", "proxy"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# Remove IE/WinInet proxy settings from registry for current user
reg_paths = [
r"HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
]
for path in reg_paths:
subprocess.run([
"reg", "delete", path, "/v", "ProxyEnable", "/f"
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run([
"reg", "delete", path, "/v", "ProxyServer", "/f"
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print("[+] Proxy settings cleared.")
input("\nPress Enter to continue...")
def flash_ip():
"""
Release and renew the IP address, and flush DNS cache.
"""
print("[*] Releasing IP address...")
subprocess.run(["ipconfig", "/release"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
time.sleep(2)
print("[*] Renewing IP address...")
subprocess.run(["ipconfig", "/renew"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
time.sleep(2)
print("[*] Flushing DNS resolver cache...")
subprocess.run(["ipconfig", "/flushdns"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print("[+] IP flush and DNS flush complete.")
input("\nPress Enter to continue...")
def disable_firewall():
"""
Turn off Windows Firewall for all profiles.
"""
print("[*] Disabling Windows Firewall for all profiles...")
subprocess.run([
"netsh", "advfirewall", "set", "allprofiles", "state", "off"
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print("[+] Windows Firewall disabled.")
input("\nPress Enter to continue...")
def clear_hosts_file():
"""
Overwrite the hosts file with default content (loopback entries only).
"""
hosts_path = r"C:\Windows\System32\drivers\etc\hosts"
default_content = "127.0.0.1\tlocalhost\n::1\tlocalhost\n"
try:
print("[*] Clearing hosts file...")
with open(hosts_path, "w") as f:
f.write(default_content)
print("[+] Hosts file reset to default.")
except PermissionError:
print("[!] Permission denied while clearing hosts file.")
input("\nPress Enter to continue...")
def clear_all_internet_settings():
"""
Execute all internet-related operations in sequence.
"""
clear_dns()
clear_proxy()
flash_ip()
disable_firewall()
clear_hosts_file()
def clear_browser_cache():
"""
Ask the user which browser’s cache to clear, then remove the cache folder.
"""
user_profile = os.environ.get("USERPROFILE", "")
browsers = {
"1": ("Google Chrome", os.path.join(
user_profile, r"AppData\Local\Google\Chrome\User Data\Default\Cache"
)),
"2": ("Mozilla Firefox", None), # Firefox cache path varies by profile
"3": ("Microsoft Edge", os.path.join(
user_profile, r"AppData\Local\Microsoft\Edge\User Data\Default\Cache"
)),
"4": ("Brave", os.path.join(
user_profile, r"AppData\Local\BraveSoftware\Brave-Browser\User Data\Default\Cache"
)),
"5": ("Opera", os.path.join(
user_profile, r"AppData\Local\Opera Software\Opera Stable\Cache"
)),
}
clear_screen()
print("=== Clear Browser Cache ===")
for key, (name, _) in browsers.items():
print(f"{key}. {name}")
print("6. Back to Internet Menu")
choice = input("Enter choice: ").strip()
if choice == "6":
return
if choice in browsers:
name, cache_path = browsers[choice]
if name == "Mozilla Firefox":
ff_base = os.path.join(user_profile, r"AppData\Local\Mozilla\Firefox\Profiles")
if os.path.isdir(ff_base):
for profile in os.listdir(ff_base):
cache_dir = os.path.join(ff_base, profile, "cache2")
if os.path.isdir(cache_dir):
try:
print(f"[*] Clearing {name} cache at {cache_dir} ...")
shutil.rmtree(cache_dir, ignore_errors=True)
print(f"[+] {name} cache cleared.")
except Exception as e:
print(f"[!] Failed to clear {name} cache: {e}")
else:
print(f"[!] Cache directory not found for profile: {profile}")
else:
print(f"[!] Firefox profiles directory not found: {ff_base}")
else:
if os.path.isdir(cache_path):
try:
print(f"[*] Clearing {name} cache at {cache_path} ...")
shutil.rmtree(cache_path, ignore_errors=True)
print(f"[+] {name} cache cleared.")
except Exception as e:
print(f"[!] Failed to clear {name} cache: {e}")
else:
print(f"[!] Cache path not found: {cache_path}")
else:
print("[!] Invalid choice.")
input("\nPress Enter to continue...")
def internet_menu():
"""
Display the Internet menu and execute corresponding actions.
"""
while True:
clear_screen()
print("=== Internet Menu ===")
print("1. Delete all DNS settings")
print("2. Delete proxy settings")
print("3. Flush IP (release, renew, flushdns)")
print("4. Disable Windows Firewall")
print("5. Clear hosts file")
print("6. Perform all of the above")
print("7. Clear browser cache")
print("8. Return to Main Menu")
choice = input("Enter your choice: ").strip()
if choice == "1":
clear_screen()
clear_dns()
elif choice == "2":
clear_screen()
clear_proxy()
elif choice == "3":
clear_screen()
flash_ip()
elif choice == "4":
clear_screen()
disable_firewall()
elif choice == "5":
clear_screen()
clear_hosts_file()
elif choice == "6":
clear_screen()
clear_all_internet_settings()
reboot_choice = input("Do you want to reboot now? (y/n): ").strip().lower()
if reboot_choice == "y":
print("[*] Rebooting the system...")
subprocess.run(["shutdown", "/r", "/t", "0"])
sys.exit(0)
else:
print("[*] Returning to Internet Menu without reboot.")
input("\nPress Enter to continue...")
elif choice == "7":
clear_screen()
clear_browser_cache()
elif choice == "8":
break
else:
print("[!] Invalid choice. Please try again.")
input("\nPress Enter to continue...")
def check_winget_available():
"""
Check if winget is available on the system.
"""
try:
subprocess.run(["winget", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return True
except FileNotFoundError:
return False
def install_program():
"""
Display categories and let the user choose a program to install via winget.
"""
if not check_winget_available():
print("[!] winget is not available on this system. Cannot install programs.")
input("\nPress Enter to continue...")
return
while True:
clear_screen()
print("=== Install Program ===")
print("1. Browsers")
print("2. Programming Software")
print("3. Essential Tools")
print("4. Back to Program Menu")
cat_choice = input("Choose a category: ").strip()
if cat_choice == "1":
browsers = {
"1": ("Google.Chrome", "Google Chrome"),
"2": ("Mozilla.Firefox", "Mozilla Firefox"),
"3": ("Microsoft.Edge", "Microsoft Edge"),
"4": ("BraveSoftware.BraveBrowser", "Brave"),
"5": ("Opera.Opera", "Opera"),
"6": ("TorBrowser.TorBrowser", "Tor Browser"),
}
clear_screen()
print("Select a browser to install:")
for key, (_, name) in browsers.items():
print(f"{key}. {name}")
print("7. Back")
b_choice = input("Enter choice: ").strip()
if b_choice in browsers:
pkg_id, name = browsers[b_choice]
print(f"[*] Installing {name} ...")
subprocess.run(["winget", "install", "--id", pkg_id, "--silent"])
print(f"[+] {name} installation command executed.")
else:
print("[*] Returning to Install Program menu.")
input("\nPress Enter to continue...")
elif cat_choice == "2":
prog_tools = {
"1": ("Python.Python.3", "Python 3"),
"2": ("Git.Git", "Git"),
"3": ("Microsoft.VisualStudioCode", "Visual Studio Code"),
"4": ("OpenJS.NodeJS", "Node.js"),
"5": ("Oracle.JavaRuntimeEnvironment", "Java JDK"),
"6": ("JetBrains.IntelliJIDEA.Community", "IntelliJ IDEA Community"),
"7": ("Microsoft.PowerShell", "PowerShell"),
"8": ("GoLang.Go", "Go"), # Winget ID for Go
"9": ("RustLang.Rust", "Rust"), # Winget ID for Rust
}
clear_screen()
print("Select a programming software to install:")
for key, (_, name) in prog_tools.items():
print(f"{key}. {name}")
print("10. Back")
p_choice = input("Enter choice: ").strip()
if p_choice in prog_tools:
pkg_id, name = prog_tools[p_choice]
print(f"[*] Installing {name} ...")
subprocess.run(["winget", "install", "--id", pkg_id, "--silent"])
print(f"[+] {name} installation command executed.")
else:
print("[*] Returning to Install Program menu.")
input("\nPress Enter to continue...")
elif cat_choice == "3":
tools = {
"1": ("7zip.7zip", "7-Zip"),
"2": ("VideoLAN.VLC", "VLC Media Player"),
"3": ("Notepad++.Notepad++", "Notepad++"),
"4": ("RARLab.WinRAR", "WinRAR"),
"5": ("Spotify.Spotify", "Spotify"),
"6": ("Zoom.Zoom", "Zoom"),
"7": ("Docker.DockerDesktop", "Docker Desktop"),
"8": ("Postman.Postman", "Postman"),
"9": ("Discord.Discord", "Discord"),
}
clear_screen()
print("Select an essential tool to install:")
for key, (_, name) in tools.items():
print(f"{key}. {name}")
print("10. Back")
t_choice = input("Enter choice: ").strip()
if t_choice in tools:
pkg_id, name = tools[t_choice]
print(f"[*] Installing {name} ...")
subprocess.run(["winget", "install", "--id", pkg_id, "--silent"])
print(f"[+] {name} installation command executed.")
else:
print("[*] Returning to Install Program menu.")
input("\nPress Enter to continue...")
elif cat_choice == "4":
break
else:
print("[!] Invalid category. Please try again.")
input("\nPress Enter to continue...")
def update_program():
"""
Display program list and let the user choose one to update via winget.
"""
if not check_winget_available():
print("[!] winget is not available on this system. Cannot update programs.")
input("\nPress Enter to continue...")
return
programs = {
"1": ("Google.Chrome", "Google Chrome"),
"2": ("Mozilla.Firefox", "Mozilla Firefox"),
"3": ("Microsoft.Edge", "Microsoft Edge"),
"4": ("BraveSoftware.BraveBrowser", "Brave"),
"5": ("Opera.Opera", "Opera"),
"6": ("TorBrowser.TorBrowser", "Tor Browser"),
"7": ("Python.Python.3", "Python 3"),
"8": ("Git.Git", "Git"),
"9": ("Microsoft.VisualStudioCode", "Visual Studio Code"),
"10": ("OpenJS.NodeJS", "Node.js"),
"11": ("Oracle.JavaRuntimeEnvironment", "Java JDK"),
"12": ("JetBrains.IntelliJIDEA.Community", "IntelliJ IDEA Community"),
"13": ("Microsoft.PowerShell", "PowerShell"),
"14": ("GoLang.Go", "Go"),
"15": ("RustLang.Rust", "Rust"),
"16": ("7zip.7zip", "7-Zip"),
"17": ("VideoLAN.VLC", "VLC Media Player"),
"18": ("Notepad++.Notepad++", "Notepad++"),
"19": ("RARLab.WinRAR", "WinRAR"),
"20": ("Spotify.Spotify", "Spotify"),
"21": ("Zoom.Zoom", "Zoom"),
"22": ("Docker.DockerDesktop", "Docker Desktop"),
"23": ("Postman.Postman", "Postman"),
"24": ("Discord.Discord", "Discord"),
}
clear_screen()
print("=== Update Program ===")
for key, (_, name) in programs.items():
print(f"{key}. {name}")
print("25. Back to Program Menu")
choice = input("Enter the number of the program to update: ").strip()
if choice in programs:
pkg_id, name = programs[choice]
print(f"[*] Updating {name} ...")
subprocess.run(["winget", "upgrade", "--id", pkg_id, "--silent"])
print(f"[+] {name} update command executed.")
else:
print("[*] Returning to Program menu.")
input("\nPress Enter to continue...")
def clear_program_cache():
"""
Display program list and let the user choose one to clear its cache.
Only a few common cache paths are defined here.
"""
user_profile = os.environ.get("USERPROFILE", "")
appdata = os.environ.get("APPDATA", "")
local_appdata = os.environ.get("LOCALAPPDATA", "")
programs = {
"1": ("Python", os.path.join(local_appdata, r"pip\Cache")),
"2": ("Git", None), # No standard cache path
"3": ("Visual Studio Code", os.path.join(appdata, r"Code\Cache")),
"4": ("Node.js", None), # Could run 'npm cache clean' instead
"5": ("Java JDK", None),
"6": ("7-Zip", None),
"7": ("VLC Media Player", None),
"8": ("Notepad++", os.path.join(appdata, r"Notepad++\cache")),
"9": ("WinRAR", None),
"10": ("Spotify", None),
"11": ("Zoom", None),
"12": ("Docker Desktop", None),
"13": ("Postman", None),
"14": ("Discord", None),
}
clear_screen()
print("=== Clear Program Cache ===")
for key, (name, _) in programs.items():
print(f"{key}. {name}")
print("15. Back to Program Menu")
choice = input("Enter the number of the program to clear cache: ").strip()
if choice in programs:
name, cache_path = programs[choice]
if cache_path and os.path.isdir(cache_path):
try:
print(f"[*] Clearing cache for {name} at {cache_path} ...")
shutil.rmtree(cache_path, ignore_errors=True)
print(f"[+] {name} cache cleared.")
except Exception as e:
print(f"[!] Failed to clear cache for {name}: {e}")
else:
print(f"[!] Cache path not defined or does not exist for {name}.")
else:
print("[*] Returning to Program menu.")
input("\nPress Enter to continue...")
def uninstall_program():
"""
Display program list and let the user choose one to uninstall via winget.
"""
if not check_winget_available():
print("[!] winget is not available on this system. Cannot uninstall programs.")
input("\nPress Enter to continue...")
return
programs = {
"1": ("Google.Chrome", "Google Chrome"),
"2": ("Mozilla.Firefox", "Mozilla Firefox"),
"3": ("Microsoft.Edge", "Microsoft Edge"),
"4": ("BraveSoftware.BraveBrowser", "Brave"),
"5": ("Opera.Opera", "Opera"),
"6": ("TorBrowser.TorBrowser", "Tor Browser"),
"7": ("Python.Python.3", "Python 3"),
"8": ("Git.Git", "Git"),
"9": ("Microsoft.VisualStudioCode", "Visual Studio Code"),
"10": ("OpenJS.NodeJS", "Node.js"),
"11": ("Oracle.JavaRuntimeEnvironment", "Java JDK"),
"12": ("JetBrains.IntelliJIDEA.Community", "IntelliJ IDEA Community"),
"13": ("Microsoft.PowerShell", "PowerShell"),
"14": ("GoLang.Go", "Go"),
"15": ("RustLang.Rust", "Rust"),
"16": ("7zip.7zip", "7-Zip"),
"17": ("VideoLAN.VLC", "VLC Media Player"),
"18": ("Notepad++.Notepad++", "Notepad++"),
"19": ("RARLab.WinRAR", "WinRAR"),
"20": ("Spotify.Spotify", "Spotify"),
"21": ("Zoom.Zoom", "Zoom"),
"22": ("Docker.DockerDesktop", "Docker Desktop"),
"23": ("Postman.Postman", "Postman"),
"24": ("Discord.Discord", "Discord"),
}
clear_screen()
print("=== Uninstall Program ===")
for key, (_, name) in programs.items():
print(f"{key}. {name}")
print("25. Back to Program Menu")
choice = input("Enter the number of the program to uninstall: ").strip()
if choice in programs:
pkg_id, name = programs[choice]
confirm = input(f"Are you sure you want to uninstall {name}? (y/n): ").strip().lower()
if confirm == "y":
print(f"[*] Uninstalling {name} ...")
subprocess.run(["winget", "uninstall", "--id", pkg_id, "--silent"])
print(f"[+] {name} uninstall command executed.")
else:
print(f"[*] Skipped uninstalling {name}.")
else:
print("[*] Returning to Program menu.")
input("\nPress Enter to continue...")
def program_menu():
"""
Display the Program menu and execute corresponding actions.
"""
while True:
clear_screen()
print("=== Program Menu ===")
print("1. Install Program")
print("2. Update Program")
print("3. Clear Program Cache")
print("4. Uninstall Program")
print("5. Return to Main Menu")
choice = input("Enter your choice: ").strip()
if choice == "1":
install_program()
elif choice == "2":
update_program()
elif choice == "3":
clear_program_cache()
elif choice == "4":
uninstall_program()
elif choice == "5":
break
else:
print("[!] Invalid choice. Please try again.")
input("\nPress Enter to continue...")
def main():
"""
Main entry point: check for admin, show banner, and display the main menu.
"""
if not is_admin():
print("[*] Administrator privileges required. Requesting elevation...")
relaunch_as_admin()
sys.exit(0)
while True:
clear_screen()
show_banner()
print("\n=== Main Menu ===")
print("1. Internet")
print("2. Program")
print("3. Exit")
choice = input("Enter your choice: ").strip()
if choice == "1":
internet_menu()
elif choice == "2":
program_menu()
elif choice == "3":
print("[*] Exiting. Goodbye!")
sys.exit(0)
else:
print("[!] Invalid choice. Please try again.")
input("\nPress Enter to continue...")
if __name__ == "__main__":
main()