forked from nazirlouis/ada_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_printer_connection.py
More file actions
52 lines (44 loc) · 1.95 KB
/
debug_printer_connection.py
File metadata and controls
52 lines (44 loc) · 1.95 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
import asyncio
import aiohttp
import sys
# Usage: python3 debug_printer_connection.py <IP>
# Example: python3 debug_printer_connection.py 10.0.0.34
async def probe(ip):
print(f"--- Probing {ip} ---")
ports = [80, 7125, 4408, 9999]
paths = ["/", "/printer/info", "/api/version", "/init_print"]
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5)) as session:
for port in ports:
print(f"\nChecking Port {port}...")
try:
# Check root first
url = f"http://{ip}:{port}/"
try:
async with session.get(url) as resp:
print(f" [ROOT] {url} -> {resp.status}")
print(f" Headers: {resp.headers}")
if resp.status == 200:
text = await resp.text()
if "<title>" in text:
title = text.split("<title>")[1].split("</title>")[0]
print(f" Title: {title}")
else:
print(" No title found in body")
except Exception as e:
print(f" [ROOT] Failed: {e}")
# Check endpoints if port seems open (optimization: only if root worked? no, API might be separate)
for path in paths:
if path == "/": continue
url = f"http://{ip}:{port}{path}"
try:
async with session.get(url) as resp:
print(f" [API] {url} -> {resp.status}")
except:
pass
except Exception as e:
print(f" Port Error: {e}")
if __name__ == "__main__":
target_ip = "10.0.0.34" # Default
if len(sys.argv) > 1:
target_ip = sys.argv[1]
asyncio.run(probe(target_ip))