Creating a script for a Telnet session?

前端 未结 11 1939
孤街浪徒
孤街浪徒 2020-11-30 02:16

Does anyone know of an easy way to create a script that can connect to a telnet server, do some usual telnet stuff, and then log off? I am dealing with users who are not fa

11条回答
  •  星月不相逢
    2020-11-30 02:56

    import telnetlib
    
    user = "admin"
    password = "\r"
    
    def connect(A):
        tnA = telnetlib.Telnet(A)
        tnA.read_until('username: ', 3)
        tnA.write(user + '\n')
        tnA.read_until('password: ', 3)
        tnA.write(password + '\n')
        return tnA
    def quit_telnet(tn)
        tn.write("bye\n")
        tn.write("quit\n")
    

提交回复
热议问题