Announcement

Collapse
No announcement yet.

Telnet Batch file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Telnet Batch file

    Hi,

    I need to send a command after I telnet to a server
    Is there a way to use a file as input to telnet? (something like the FTP -s) ...

    Thanks

  • #2
    Re: Telnet Batch file

    As far as I know, no there isn't. The trouble with Telnet is that the only "signal" you get back from the server is the text displayed at the terminal. Your script would have no way of knowing when to send the username, password and command to be executed - send them too early, and authentication fails, send them too late and the server may have already closed the connection.
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

    Comment


    • #3
      Re: Telnet Batch file

      I've done this using Procomm, which has a scripting language for this purpose. It allows for input to wait for prompts such as password or other keywords which trigger input. There are probably other programs that can do this too.
      Last edited by ahinson; 24th December 2008, 20:41.
      Andrew

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment


      • #4
        Re: Telnet Batch file

        What are you opening a telnet session to? Telnet is insecure and really shouldn't be used anymore if you can avoid it. SSH provides encryption and can also take commands without opening a full session.

        Comment


        • #5
          Re: Telnet Batch file

          Hi, Just FYI - I managed to do it with powershell - if someone else will ever wanted to know how to...


          here is the script:

          Code:
          #param([String] $remoteHost =$(throw "Please specify the Target Server"),[String] $port = $(throw "Please specify the port"))
          
          param([String] $remoteHost,[String] $port)
          
          
          if ($remotehost -eq "" -or $port -eq "") 
          {
          "Please specify the Target Server and port"
           return; 
          }
          
          $socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port) 
          if($socket -eq $null) { return; } 
          
          $stream = $socket.GetStream() 
          $writer = new-object System.IO.StreamWriter($stream) 
          $buffer = new-object System.Byte[] 1024 
          
          $writer.WriteLine("Bla bla bla bla")
          $writer.WriteLine("Bla bla bla bla")
          $writer.WriteLine("Bla bla bla bla")
          
          $writer.Flush()
          
          ## Close the streams 
          $writer.Close() 
          $stream.Close()

          Comment


          • #6
            Re: Telnet Batch file

            Cool that you got it working with Powershell. Thanks for sharing how too.
            Andrew

            ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

            Comment

            Working...
            X