File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments