-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_optimization.py
More file actions
89 lines (68 loc) · 2.68 KB
/
verify_optimization.py
File metadata and controls
89 lines (68 loc) · 2.68 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
#!/usr/bin/env python3
# verify_optimization.py
# This script preforms the tests in which I use to verify that the system and the
# connections from my internal network to my external network are optimized for my
# python IDE.
# The tests include: Testing DNS resolution, Testing the disk I/O, Testing pip connectivity
# Written by: JakeTheSnake(JMG3000)
import socket
import time
import os
import shutil
import urllib.request
# hostname can be changed per use case.
def test_dns(hostname="pypi.org"):
print(f"\n[1] Testing DNS Resolution for {hostname} (Cloudflare Check)...")
start = time.perf_counter()
try:
ip = socket.gethostbyname(hostname)
end = time.perf_counter()
duration_ms = (end - start) * 1000
print(f" SUCCESS: Resolved to {ip}")
print(f" TIME: {duration_ms:.2f} ms")
if duration_ms < 50:
print(" VERDICT: EXCELLENT (Cloudflare 1.1.1.1 is active)")
else:
print(" VERDICT: SLOW (Might still be using ISP DNS)")
except socket.error as e:
print(f" FAIL: Could not resolve {hostname}. Error: {e}")
def test_io_speed():
print(f"\n[2] Testing Disk I/O (Defender Exclusion Check)...")
test_dir = "defender_test_temp"
if os.path.exists(test_dir):
shutil.rmtree(test_dir)
os.makedirs(test_dir)
print(" Writing 1,000 small files (Simulating compilation)...")
start = time.perf_counter()
for i in range(1000):
with open(os.path.join(test_dir, f"test_{i}.txt"), "w") as f:
f.write("import this\n" * 10)
end = time.perf_counter()
duration = end - start
print(f" TIME: {duration:.4f} seconds")
# Cleanup
shutil.rmtree(test_dir)
if duration < 1.0:
print(" VERDICT: BLAZING FAST (Defender is likely ignoring this folder)")
elif duration < 3.0:
print(" VERDICT: ACCEPTABLE (Standard overhead)")
else:
print(" VERDICT: SLOW (Defender might be scanning every file write. Check Exclusions.)")
def test_connectivity():
print(f"\n[3] Testing Pip Connectivity (SSL Handshake)...")
url = "https://pypi.org"
start = time.perf_counter()
try:
with urllib.request.urlopen(url, timeout=5) as response:
end = time.perf_counter()
print(f" STATUS: {response.getcode()} OK")
print(f" TIME: {(end - start):.4f} seconds")
print(" VERDICT: CONNECTED")
except Exception as e:
print(f" FAIL: {e}")
if __name__ == "__main__":
print("=== SYSTEM OPTIMIZATION VERIFICATION ===")
test_dns("google.com")
test_connectivity()
test_io_speed()
print("\n=== TEST COMPLETE ===")