• Script a telnet session (Windows XP SP2)

    Home » Forums » AskWoody support » Windows » Windows Vista, XP and earlier » Questions: Vista, XP back to 3.1 » Script a telnet session (Windows XP SP2)

    Author
    Topic
    #445503

    My network router has a problem which I can work around by logging in on a telnet session and issuing some commands. I need to reissue these commands anytime the router is reset, so I would like to create a .BAT file that automates this.

    Can anyone share an example of a simple .BAT file that connects via telnet and passes commands via the telnet session?

    (here is a log of me issuing these commands manually, IP address and username changed to protect my privacy)

    C:> telnet 10.0.0.254

    Username : userx
    Password : ************
    _{userx}=>system config digestauth disabled
    {userx}=>saveall
    {userx}=>exit

    Connection to host lost.

    C:> EXIT

    StuartR

    Viewing 1 reply thread
    Author
    Replies
    • #1080358

      Stuart

      I’ve done this with FTP, but never with Telnet, so I don’t know how it will react.

      Basically you would create a ‘command’ file via a BATch file, then point it at Telnet.

      (
      echo userx
      echo password
      echo system config digestauth disabled
      echo saveall
      echo exit
      ) > telnet.lns
      
      telnet 10.0.0.254 < telnet.lns

      Try the concept with something innocuous (e.g. just do userx/password/exit as the first test!)

      • #1080410

        Unfortunately the telnet client doesn’t seem to read from the input file at all. This isn’t helped by the fact that the telnet client starts by clearing the screen!

        For a very simple test, I created a file called telnet.txt with username, password and exit, I then entered the command
        telnet < telnet.txt

        from a command prompt and it responded by clearing the screen and outputting

        Welcome to Microsoft Telnet Client

        Escape Character is 'CTRL+]'

        Microsoft Telnet> Microsoft Telnet>
        C:Temp>

        Regardless of what text I put in the “input file” I just get this same output.

        StuartR

    • #1080438

      I don’t know if it’s of any use in your situation, but PuTTY: a free telnet/ssh client allows you to Save then Load telnet sessions, to produce the sort of result you’re looking for.

      Alan

      • #1080443

        Alan,

        PuTTy won’t do what I need, because it’s a GUI product, but the PuTTy page had a command line tool called plink that did exactly what I needed when combined with John’s instructions for redirecting the input stream.

        Thanks to both of you.

        StuartR

        • #1080448

          Sorry, I have used plink myself, but mixed the tools when I referenced them. stupidme

          Alan

          • #1080451

            I have used PuTTy before, as an interactive SSH client, and nearly replied saying that it wouldn’t do what I needed, lucky I actually looked around on their web site first! Thank you.

            StuartR

        • #1080467

          Stuart

          Glad the combined effort produced satisfactory results! (In 25 years of playing with PCs and servers I think I have used Telnet just once…)

          • #1080478

            Telnet used to be my favourite tool for testing early web servers, just telnet to port 80 and get index.htm

            StuartR

            • #1080480

              Strange coincidence. I was just trying that method to reveal the “real” URL in a tinyurl link (as per Scriptlets for URL preprocessing). I can’t get a port 80 connection though. Maybe they got sick of everyone telnetting their server ???

              Alan

    Viewing 1 reply thread
    Reply To: Script a telnet session (Windows XP SP2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: