Results 1 to 4 of 4

Thread: Scripting windows Telnet

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,785

    Scripting windows Telnet

    Some time ago I was looking for and couldn’t find a way to have scripted telnet sessions for someone I know who works in air conditioning that said he could really use one. Now that I have a solution id like to share it…someone might need it someday who knows.

    An easy way to do this is in notepad.

    Write all the commands down as if it were a batch file and be sure to add a new line at the end to execute the last command. Select all, copy and paste it right into the telnet session. If you running 2k you can do this by simply right clicking on the DOS window after coping from notepad. The buffer will enter and execute each command in turn. The XP command window opens an options menu when right clicked so just select paste. (this is the feature I hate most about XP)

    Save it with a descriptive name if you think your might need it in the future.

    If you’ve flipped out and want to use telnet as your mail client for some reason or check for open relays this can save allot of time

    I know everyone’s going to say telnet this and telnet that, but the reason that im passing this on to those who aren’t aware of it is…. This can be done with any command line program that doesn’t have a gui.

    If I have to make a change to all the computers on the network. I use a for loop, psexec and a list of computers (FOR /f “tokens=1” %X in (allcomps.txt) do psexec %X –s cmd). Copy the commands once (last command being exit followed by a new line) and just right-click on the dos window every time a shell opens. Great for changing .ini files or copying a new shortcut to everyone’s desktop.
    Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”

  2. #2
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Thanks for sharing this trick. In this context, you could also try to use a WScript-file,
    by making use of SendKeys[1], if scripting is allowed.

    You can automatically connect to as many hosts as you wish and perform what you
    want to do without any further interaction.

    The core program, which I did for educational purposes, is given by

    Code:
    @ECHO OFF
      :: :::::::::::::::::::::::::::::::::::::::::::::
      :: temp_SendKeys.VBS will contain the "commands"
      ECHO.set handler=WScript.CreateObject("WScript.Shell")>temp_SendKeys.VBS
      ECHO.WScript.sleep 500 >>temp_SendKeys.VBS
    
    
      :: :::::::::::::::::::::::::::::::::::::::::::::
      :: Open Connection To Telnet Host
      ECHO.handler.SendKeys "open telnet.com~" >>temp_SendKeys.VBS
      ECHO.WScript.sleep 500 >>temp_SendKeys.VBS
    
    
      :: :::::::::::::::::::::::::::::::::::::::::::::
      :: Send Login Name
      ECHO.handler.SendKeys "mylogin~" >>temp_SendKeys.VBS
      ECHO.WScript.sleep 500 >>temp_SendKeys.VBS
      :: Send Password
      ECHO.handler.SendKeys "mypassword~" >>temp_SendKeys.VBS
      ECHO.WScript.sleep 500 >>temp_SendKeys.VBS
      
    
      :: :::::::::::::::::::::::::::::::::::::::::::::
      :: Send Stuff to be done
      ECHO.handler.SendKeys "dir~" >>temp_SendKeys.VBS
      ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS
    
    
      :: :::::::::::::::::::::::::::::::::::::::::::::
      :: Logout
      ECHO.handler.SendKeys "exit~" >>temp_SendKeys.VBS
      ECHO.WScript.sleep 250 >>temp_SendKeys.VBS
      ECHO.handler.SendKeys " " >>temp_SendKeys.VBS
      ECHO.WScript.sleep 250 >>temp_SendKeys.VBS
      ECHO.handler.SendKeys "quit~" >>temp_SendKeys.VBS
      ECHO.WScript.sleep 250 >>temp_SendKeys.VBS
    
    
      :: Open a Telnet Windows
      start telnet.EXE
    
    
      :: Run the script
      cscript//nologo temp_SendKeys.VBS
    
    
      :: Delete the temporary file 
      DEL temp_SendKeys.VBS
    which I tested on a Windows XP Pro system. Copy past and save as
    .bat file. As suggested, you could also use this to telnet to port 25,
    therefore no password might be needed.

    Cheers.

    [1] http://msdn.microsoft.com/library/de...thsendkeys.asp
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  3. #3
    Junior Member
    Join Date
    Feb 2008
    Posts
    1
    AMAZING!

    I know this is an old post and i had i bit of trouble findig it.. but it was worth it.

    It is strange that noone else seems to know your solution to automating (Microsoft) telnet.. You deserve a medal!!

    Thanks alot..

    /Orvar

  4. #4
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    Oliver's Law:
    Experience is something you don't get until just after you need it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •