running "telnet" within a batch file
Results 1 to 4 of 4

Thread: running "telnet" within a batch file

  1. #1
    Junior Member
    Join Date
    Apr 2005
    Posts
    2

    running "telnet" within a batch file

    I'm creating a batch file to change some routes in our network.

    When it gets to the telnet portion, it doesn't enter the passwords.

    here is the example..



    cd \

    rem .


    COLOR 0E

    @ECHO OFF

    cls

    ECHO THIS BATCH FILE WILL REROUTE ALL ADP-SIS TRAFFIC TO HOUSTON


    pause

    ECHO ARE YOU SURE YOU WANT TO PROCEED?

    pause

    ECHO ARE YOU POSITIVE?

    pause


    telnet 104.109.12.119
    testing
    enable
    testing
    conf t
    no ip route 129.23.132.0 255.255.255.0
    ip route 129.23.132.0 255.255.255.0 10.1.30.6
    exit


    ECHO Changing core router in Dallas.


    ECHO Done.


    ECHO Changing Configuration on the Tasman in Dallas


    ECHO Done.


    ECHO Changing Configuration on the Tasman in Houston

    ECHO Done.

    ECHO ALL TRAFFIC ROUTING CHANGED TO HOUSTON.
    ECHO ALL TRAFFIC ROUTING CHANGED TO HOUSTON.

    pause



    It will stop after the telnet command and wait for me to enter the password when I have it in the script automatically.

    This batch file is being used in windows.

    -papa

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

    By running telnet, your script passes the sceptre of power
    to telnet. It will wait until telnet exits. Well, windows shell
    is not unix shell But still, you can do a lot with it!

    For me, the most practical way is to create a WScript in a batch-file,
    making use of the SendKeys method. See a recent example[1]
    I have written a couple of days ago.

    Good luck.

    Cheers.

    [1] http://www.antionline.com/showthread...534#post835534
    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
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Perl makes it easy (and OS independent):

    Code:
    use Net::Telnet;
    
    $t = Net::Telnet->new( Timeout => 10, Prompt => '>');
    
    $t->open("myrouter");
    $t->login("username", "password");
    
    $commands = "conf t\n".
                   "no ip route 129.23.132.0 255.255.255.0\n".
                   "ip route 129.23.132.0 255.255.255.0 10.1.30.6\n";
    
    @response = $t->cmd("$commands");
    
    print @response;
    But you might want to give the commands line by line so you can check the response.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  4. #4
    Junior Member
    Join Date
    Apr 2005
    Posts
    2
    Originally posted here by sec_ware
    Hi papalokey

    By running telnet, your script passes the sceptre of power
    to telnet. It will wait until telnet exits. Well, windows shell
    is not unix shell But still, you can do a lot with it!

    For me, the most practical way is to create a WScript in a batch-file,
    making use of the SendKeys method. See a recent example[1]
    I have written a couple of days ago.

    Good luck.

    Cheers.

    [1] http://www.antionline.com/showthread...534#post835534
    Thanks a lot! Thanks a TON!

    It works like a champ!

    Thx man..

    -papa

Posting Permissions

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

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides