Skip to content

Commit fc2b4ce

Browse files
authored
Add telnet_tutor.py for Telnet demonstration
This script connects to a public Telnet server for educational purposes, demonstrating basic Telnet commands and handling connection errors.
1 parent 25e19c6 commit fc2b4ce

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

ForNicole/tools/telnet_tutor.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
telnet_tutor.py — gentle Telnet demonstration.
3+
Educational use only — no live system access.
4+
"""
5+
6+
import telnetlib
7+
import time
8+
9+
HOST = "telehack.com" # a public sandboxed telnet playground
10+
11+
def connect_demo():
12+
print("🌐 Connecting to Telehack (a safe retro sandbox)...")
13+
tn = telnetlib.Telnet(HOST)
14+
time.sleep(1)
15+
banner = tn.read_until(b":", timeout=5).decode(errors="ignore")
16+
print("Server says:\n", banner.strip())
17+
tn.write(b"help\n")
18+
time.sleep(1)
19+
data = tn.read_very_eager().decode(errors="ignore")
20+
print("----- Help excerpt -----")
21+
print("\n".join(data.splitlines()[:20]))
22+
tn.write(b"quit\n")
23+
tn.close()
24+
print("Disconnected gracefully.")
25+
26+
if __name__ == "__main__":
27+
try:
28+
connect_demo()
29+
except Exception as e:
30+
print("❌ Connection error:", e)

0 commit comments

Comments
 (0)