'python code for making telnet connection to NSK machine
I am not able to do telnet connection to my server. I am able to do it manually but through program it is not happening.
Below is the code from cmd which works fine -
C:\Users\Administrator>telnet <host>
WELCOME TO BRAMHA [PORT $ZTC0 #23 WINDOW $ZTN0.#PTUEAKH]
TELSERV - T9553J01 - (25JUN2009)
Available Services:
TACL EXIT
Enter Choice> TACL
TACL 1> logon super.super
Password:
Last Logon: 01 MAR 2022, 00:34
1> exit
Are you sure you want to stop this TACL (\BRAMHA.$X7A2)?yes
Connection to host lost.
C:\Users\Administrator>
I tried below Python code-
import os,re,telnetlib
host = "abc.com"
tn = telnetlib.Telnet(host)
tn.read_until(b"Enter Choice>", timeout=10) # <- add this line
# tn.read_until(b"> ", timeout=10) # if prompt has space behind
#tn.write(b"exit\n")
tn.write(b"tacl\n")
tn.read_until(b"TACL 1>", timeout=10)
tn.write(b"logon super.super\n")
tn.read_until(b"Password:", timeout=10)
tn.write(b"123abc\n")
tn.read_until(b"1>", timeout=10)
tn.write(b"exit\n")
tn.read_until(b"*?", timeout=10)
tn.write(b"yes\n")
x = tn.read_all()
print (x)
but while executing it is simply waiting and nothing is happening.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
