Creating a script for a Telnet session?

前端 未结 11 1941
孤街浪徒
孤街浪徒 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 03:09

    I like the example given by Active State using python. Here is the full link. I added the simple log in part from the link but you can get the gist of what you could do.

    import telnetlib
    
    prdLogBox='142.178.1.3'
    uid = 'uid'
    pwd = 'yourpassword'
    
    tn = telnetlib.Telnet(prdLogBox)
    tn.read_until("login: ")
    tn.write(uid + "\n")
    tn.read_until("Password:")
    tn.write(pwd + "\n")
    tn.write("exit\n")
    tn.close()
    

提交回复
热议问题