Repository navigation
Expand file tree
/
Copy pathnetwork_checker_pro.py
More file actions
154 lines (128 loc) · 4.46 KB
/
Copy pathnetwork_checker_pro.py
File metadata and controls
154 lines (128 loc) · 4.46 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
import socket
import subprocess
import platform
import time
# ------------------------------
# Utility: Ping Test
# ------------------------------
def ping(host):
param = "-n" if platform.system().lower() == "windows" else "-c"
try:
result = subprocess.run(["ping", param, "1", host],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True, timeout=5)
return result.returncode == 0
except (OSError, subprocess.TimeoutExpired):
return False
# ------------------------------
# Utility: TCP Port Test
# ------------------------------
def tcp_test(host, port, timeout=3):
try:
with socket.create_connection((host, port), timeout):
pass
return True
except OSError:
return False
# ------------------------------
# Utility: HTTP GET Test (Raw Socket)
# ------------------------------
def http_test(host):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(3)
s.connect((host, 80))
request = f"GET / HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\n\r\n"
s.sendall(request.encode())
response = s.recv(50)
return response.startswith(b"HTTP/")
except OSError:
return False
# ------------------------------
# Detect Local IP
# ------------------------------
def get_local_ip():
try:
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
except OSError:
return "Unknown"
# ------------------------------
# Network Class (A / B / C)
# ------------------------------
def get_network_class(ip):
try:
first = int(ip.split(".")[0])
if 1 <= first <= 126:
return "Class A"
elif 128 <= first <= 191:
return "Class B"
elif 192 <= first <= 223:
return "Class C"
else:
return "Other"
except:
return "Unknown"
# ------------------------------
# MAIN PROGRAM
# ------------------------------
def main():
print("\n🌐 UNIVERSAL NETWORK CHECKER PRO")
print("────────────────────────────────────\n")
# List of websites to test (FULLY CUSTOMIZABLE)
websites = [
"google.com",
"youtube.com",
"cloudflare.com",
"microsoft.com",
"hamrah.academy", # You can add/remove any domain
]
# Basic System Info
local_ip = get_local_ip()
print(f"📌 Local IP: {local_ip}")
print(f"📌 Network Class: {get_network_class(local_ip)}\n")
print("🔍 Checking Global Internet...\n")
time.sleep(1)
# Test Public Internet via pinging common DNS servers
dns_servers = ["8.8.8.8", "1.1.1.1"]
internet_status = False
for dns in dns_servers:
print(f"➡️ Pinging DNS {dns} ...")
if ping(dns):
print(" ✅ DNS reachable\n")
internet_status = True
break
else:
print(" ❌ Failed\n")
if not internet_status:
if any(tcp_test(host, 443) for host in dns_servers):
print("TCP connectivity is available; ICMP may be blocked or unavailable.\n")
else:
print("Connectivity to the tested endpoints could not be confirmed.\n")
print("🌍 Testing Websites...\n")
for site in websites:
print(f"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
print(f"🌐 Testing: {site}")
# Ping test
if ping(site):
print(" 📡 Ping: ✅ OK")
else:
print(" 📡 Ping: ❌ Fail")
# TCP test (HTTPS)
if tcp_test(site, 443):
print(" 🔐 TCP 443: ✅ OK")
else:
print(" 🔐 TCP 443: ❌ Fail")
# HTTP GET test
if http_test(site):
print(" 🌍 HTTP GET: ✅ OK")
else:
print(" 🌍 HTTP GET: ❌ Fail")
print()
print("────────────────────────────────────")
print("✔ TEST FINISHED — Developed by Milad Hadad")
print("────────────────────────────────────\n")
if __name__ == "__main__":
main()