telnet to router

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravimath
    New Member
    • Sep 2009
    • 14

    telnet to router

    Dear all,
    I have written following script to loin to router bu it is showing error.

    Code:
    #!c:\Perl\bin;
    use strict;
    use warnings;
    
     my $hostname = '[I]REMOVED FOR YOUR PROTECTION[/I]';
     my $password = '[I]REMOVED FOR YOUR PROTECTION[/I]';
    
    use Net::Telnet();
     my $telnet = new Net::Telnet ( Timeout=>40,Errmode=>'die');
    $telnet->open($hostname);
    $telnet->waitfor('/Password: $/i');
    print ("printing password");
    $telnet->print($password);
    $telnet->waitfor('/Router> $/i');
    print ("getting admin rights");
    $telnet->print('en');
    $telnet->waitfor('/Password: $/i');
    $telnet->print($password);
    print ("printing password");
    $telnet->waitfor('/Router#: $/i');
    Can't locate object method "new" via package "Net::Telne t" (perhaps you forgot t
    o load "Net::Telne t"?) at h.pl line 9.


    pls help me to rectify the problem
    Last edited by numberwhun; Sep 13 '09, 08:35 PM. Reason: Please use code tags! Removed sensitive information.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by ravimath
    Dear all,
    I have written following script to loin to router bu it is showing error.

    Code:
    #!c:\Perl\bin;
    use strict;
    use warnings;
    
     my $hostname = '[I]REMOVED FOR YOUR PROTECTION[/I]';
     my $password = '[I]REMOVED FOR YOUR PROTECTION[/I]';
    
    use Net::Telnet();
     my $telnet = new Net::Telnet ( Timeout=>40,Errmode=>'die');
    $telnet->open($hostname);
    $telnet->waitfor('/Password: $/i');
    print ("printing password");
    $telnet->print($password);
    $telnet->waitfor('/Router> $/i');
    print ("getting admin rights");
    $telnet->print('en');
    $telnet->waitfor('/Password: $/i');
    $telnet->print($password);
    print ("printing password");
    $telnet->waitfor('/Router#: $/i');
    Can't locate object method "new" via package "Net::Telne t" (perhaps you forgot t
    o load "Net::Telne t"?) at h.pl line 9.


    pls help me to rectify the problem
    Try removing the parenthesis after the module name, as such:

    Code:
    use Net::Telnet;
    They are not needed and are probably causing your problem.

    Also, please do not include sensitive information in your posts (such as login information and IP Addresses). That is a security risk that you should always be wary of. I have removed them for you in your post.

    Regards,

    Jeff

    Comment

    • ravimath
      New Member
      • Sep 2009
      • 14

      #3
      I have tried removing parenthesis, but still it gives same error.
      thanks for your help

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Did you properly install the Net::Telnet module? Your code is right out of the modules example code so that shouldn't be the problem, so maybe the module installation wasn't done properly.

        Comment

        • ravimath
          New Member
          • Sep 2009
          • 14

          #5
          Router telnet

          can u tell me how to check whether i have installed install the Net::Telnet module properly or not ? rather tell me how to install install the Net::Telnet module.

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            Originally posted by ravimath
            can u tell me how to check whether i have installed install the Net::Telnet module properly or not ? rather tell me how to install install the Net::Telnet module.
            All the questions you have asked can be answered in the CPAN FAQ. It has a lot of good information. You can also find out how to figure out what modules are already installed.

            Regards,

            Jeff

            Comment

            • ravimath
              New Member
              • Sep 2009
              • 14

              #7
              I have read cpan.faq , but it is not having sufficient info , regarding net::telnet installation on windows platform using ppm or any other method
              can u tell me how to check whether i have installed install the Net::Telnet module properly or not ? rather tell me how to install install the Net::Telnet module.
              pls help

              Comment

              • ravimath
                New Member
                • Sep 2009
                • 14

                #8
                i have resolved following problemCan't locate object method "new" via package "Net::Telne t" (perhaps you forgot t
                o load "Net::Telne t"?) at h.pl line 9., but now when i run that original script
                it waits for getting input and after getting input it gives following error
                'sfddg' is not recognized as an internal or external command,
                operable program or batch file.
                when i type something it shows nothing on screen , but it takes input.
                even when i run another small script which includesonly one line
                print $wkday;
                it just returns to command prompt and does not show anything on screen

                2)can u suggest some modifications, i want to achieve following
                It should prompt for ip address of router , then ask for username , password and enable password and finally it should give output on screen of sh run of that router

                Comment

                • numberwhun
                  Recognized Expert Moderator Specialist
                  • May 2007
                  • 3467

                  #9
                  Originally posted by ravimath
                  i have resolved following problemCan't locate object method "new" via package "Net::Telne t" (perhaps you forgot t
                  o load "Net::Telne t"?) at h.pl line 9., but now when i run that original script
                  it waits for getting input and after getting input it gives following error
                  'sfddg' is not recognized as an internal or external command,
                  operable program or batch file.
                  when i type something it shows nothing on screen , but it takes input.
                  even when i run another small script which includesonly one line
                  print $wkday;
                  it just returns to command prompt and does not show anything on screen

                  2)can u suggest some modifications, i want to achieve following
                  It should prompt for ip address of router , then ask for username , password and enable password and finally it should give output on screen of sh run of that router
                  For the modifications in #2, that should be quite simple for you to add. Why not try and post your code if you get stuck. Its just a simple matter of prompting the user and storing the answer(s).

                  Regards,

                  Jeff

                  Comment

                  • ravimath
                    New Member
                    • Sep 2009
                    • 14

                    #10
                    Code:
                    #!c:\Perl\bin; 
                    use strict; 
                    use warnings; 
                      
                     my $hostname = 'REMOVED FOR YOUR PROTECTION'; 
                     my $password = 'REMOVED FOR YOUR PROTECTION'; 
                      
                    use Net::Telnet(); 
                     my $telnet = new Net::Telnet ( Timeout=>40,Errmode=>'die'); 
                    $telnet->open($hostname); 
                    $telnet->waitfor('/Password: $/i'); 
                    print ("printing password"); 
                    $telnet->print($password); 
                    $telnet->waitfor('/Router> $/i'); 
                    print ("getting admin rights"); 
                    $telnet->print('en'); 
                    $telnet->waitfor('/Password: $/i'); 
                    $telnet->print($password); 
                    print ("printing password"); 
                    $telnet->waitfor('/Router#: $/i');
                    I have already added this code pls suggest changes for my previous question
                    Last edited by numberwhun; Sep 22 '09, 12:29 PM. Reason: Please use code tags!

                    Comment

                    • nithinpes
                      Recognized Expert Contributor
                      • Dec 2007
                      • 410

                      #11
                      That should be simple.
                      Code:
                      print "\nEnter Router IP:";
                      $hostname=<STDIN>;
                      print "\nEnter password:";
                      $password=<STDIN>;

                      Comment

                      • numberwhun
                        Recognized Expert Moderator Specialist
                        • May 2007
                        • 3467

                        #12
                        Ravimath, you need to PLEASE use code tags around your code that you put into the forums. It is not optional and is required. If you do not do it, we have to clean up behind you. If you notice your original post, you will see I did it there as well.

                        Regards,

                        Jeff

                        Comment

                        • ravimath
                          New Member
                          • Sep 2009
                          • 14

                          #13
                          what is code tags ? pls help regarding this . i am sorry b
                          coz i am new to this

                          Comment

                          • toolic
                            Recognized Expert New Member
                            • Sep 2009
                            • 70

                            #14
                            Code tags are used to distinguish plain text from Perl code snippets
                            in your posting. They help others to more clearly understand your question.
                            When you are typing your question into this forum, you should see
                            several icons above the box where you are typing. The icon that looks
                            like # will automatically add a pair of CODE tags for you.

                            It would also help others to more clearly understand your question
                            if you used full English words rather than abbreviations. For example,
                            "please" is clearer than "pls".

                            Comment

                            • numberwhun
                              Recognized Expert Moderator Specialist
                              • May 2007
                              • 3467

                              #15
                              In addition, here is a link to the posting guidelines for asking a question, which fully explains code tags.

                              Regards,

                              Jeff

                              Comment

                              Working...