Creating a script for a Telnet session?

前端 未结 11 1922
孤街浪徒
孤街浪徒 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:45

    This vbs script reloads a cisco switch, make sure telnet is installed on windows.

    Option explicit
    Dim oShell
    set oShell= Wscript.CreateObject("WScript.Shell")
    oShell.Run "telnet"
    WScript.Sleep 1000
    oShell.Sendkeys "open 172.25.15.9~"
    WScript.Sleep 1000
    oShell.Sendkeys "password~"
    WScript.Sleep 1000
    oShell.Sendkeys "en~"
    WScript.Sleep 1000
    oShell.Sendkeys "password~"
    WScript.Sleep 1000
    oShell.Sendkeys "reload~"
    WScript.Sleep 1000
    oShell.Sendkeys "~"
    Wscript.Quit
    
    0 讨论(0)
  • 2020-11-30 02:52

    Bash shell supports this out-of-box, e.g.

    exec {stream}<>/dev/tcp/example.com/80
    printf "GET / HTTP/1.1\nHost: example.com\nConnection: close\n\n" >&${stream}
    cat <&${stream}
    

    To filter and only show some lines, run: grep Example <&${stream}.

    0 讨论(0)
  • 2020-11-30 02:54

    It may not sound a good idea but i used java and used simple TCP/IP socket programming to connect to a telnet server and exchange communication. ANd it works perfectly if you know the protocol implemented. For SSH etc, it might be tough unless you know how to do the handshake etc, but simple telnet works like a treat.

    Another way i tried, was using external process in java System.exec() etc, and then let the windows built in telnet do the job for you and you just send and receive data to the local system process.

    0 讨论(0)
  • 2020-11-30 02:56

    Check for the SendCommand tool.

    You can use it as follows:

    perl sendcommand.pl -i login.txt -t cisco -c "show ip route"
    
    0 讨论(0)
  • 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")
    
    0 讨论(0)
  • 2020-11-30 02:57

    Write the telnet session inside a BAT Dos file and execute.

    0 讨论(0)
提交回复
热议问题