telnetlib python example

后端 未结 6 1826
走了就别回头了
走了就别回头了 2020-12-08 05:26

So I\'m trying this really simple example given by the python docs:

import getpass
import sys
import telnetlib

HOST = \"\"
user = raw_input(\         


        
6条回答
  •  遥遥无期
    2020-12-08 06:16

    I know this is late to post but may help others. I also struggled to get this right but here is my piece of code. My telnet would follow certain flow like it would ask for loginID and then Password and then you have to wait for a particular string to be displayed here,which for my case was "DB>" then you can proceed with the command and all. My output would be saved in "out" varible

    import os,re,telnetlib
    host = "10.xxx.xxx.xxx"
    port = 23
    
    telnet = telnetlib.Telnet()
    telnet.open(host, port)
    telnet.write('loginID\r\n')
    telnet.write('Password\r\n')
    out = telnet.read_until("DB>", 5)
    telnet.write('show cable modem reg\r\n') #Mycommand
    out = telnet.read_until("DB>", 5)
    telnet.write('quit\r\n')
    telnet.close()
    

    For more variations and help, Check the website nullege

提交回复
热议问题