some usage doubts on net::telnet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    some usage doubts on net::telnet

    hi guys,
    a question on net::telnet
    what does this module do?
    cos i have a telnet client that will be able to communicate with a database
    so is it true if i enter my ip address, username, and password and using print later again to execute some commands
    i will get some results on some screen??



    [CODE=perl]
    use Net::Telnet;

    $telnet3 = new Net::Telnet;
    $telnet3->open('IP_ADDRE SS'); # Substituted fake IP
    $telnet3->waitfor('/Enter login: $/i');
    $telnet3->print('USERNAM E'); # Substituted fake User
    $telnet3->waitfor('/Enter password: $/i');
    $telnet3->print('PASSWOR D'); # Substituted fake PW

    print "Logged in to device\n";
    [/CODE]
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by poolboi
    hi guys,
    a question on net::telnet
    what does this module do?
    cos i have a telnet client that will be able to communicate with a database
    so is it true if i enter my ip address, username, and password and using print later again to execute some commands
    i will get some results on some screen??



    [CODE=perl]
    use Net::Telnet;

    $telnet3 = new Net::Telnet;
    $telnet3->open('IP_ADDRE SS'); # Substituted fake IP
    $telnet3->waitfor('/Enter login: $/i');
    $telnet3->print('USERNAM E'); # Substituted fake User
    $telnet3->waitfor('/Enter password: $/i');
    $telnet3->print('PASSWOR D'); # Substituted fake PW

    print "Logged in to device\n";
    [/CODE]
    If you read the page, you will find that the print() function of that module will write what you put in there, specifically after the connection is made. What you want is the login() function to log in. The CPAN page shows you how to use this module.

    Regards,

    Jeff

    Comment

    • poolboi
      New Member
      • Jan 2008
      • 170

      #3
      hi guys,
      alright i tried to see if my connection works using the following code
      but when i use the program it apparents open the perl command line interpreter that just waits for some time before closing the interpreter

      i dunno what was happening but apparently my guess it timeout cos there's some errors

      is there any way to check if i'm connected to the IP i stated?

      [CODE=perl]
      use Net::Telnet;

      $telnet3 = new Net::Telnet(tim eout => 10,
      Errmode => 'die');

      $telnet3->open('IP_ADDRE SS');
      $telnet3->login(username , password);
      @lines = $telnet3->cmd("who");


      open(FILE, ">file.txt" );

      print FILE ("@lines\n") ;
      [/CODE]

      Comment

      • nithinpes
        Recognized Expert Contributor
        • Dec 2007
        • 410

        #4
        You can catch the errors as below:

        Code:
        $telnet3->open('IP_ADDRESS') or die "failed to connect:$!"; 
        $telnet3->login(username, password) or die "login failed:$!";

        Comment

        • poolboi
          New Member
          • Jan 2008
          • 170

          #5
          hm..tried that
          still the same
          like a the perl interpreter screen comes up
          and after the default timeout of 10
          the screen closes
          no errors caught and i still got no idea if connection is made
          pls help

          Comment

          • nithinpes
            Recognized Expert Contributor
            • Dec 2007
            • 410

            #6
            Originally posted by poolboi
            hm..tried that
            still the same
            like a the perl interpreter screen comes up
            and after the default timeout of 10
            the screen closes
            no errors caught and i still got no idea if connection is made
            pls help
            Before trying to catch the error, you need to change Errmode in the line where you are creating new instance of object.

            Code:
            $telnet3 = new Net::Telnet(timeout => 10,
                            Errmode => 'return');

            Comment

            • poolboi
              New Member
              • Jan 2008
              • 170

              #7
              right..i've actually done what u have said to try and catch the error
              but i think there's a problem
              the screen display the error and then closes it in 1 sec
              it's almost impossible to see the error msg
              any one experience this kind of problem before?
              i'm using activestate perl 5.10 on windows XP

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                check your Windows firewall ( or any other one you may have running) and see if it is blocking telnat access. If you don't know how to check consult your Windows XP help files.

                Also, don't double-click on your perl file to run it. Open a DOS window and type in:

                Code:
                c:\>perl yourscript.pl
                provide full paths if necessary

                Code:
                c:\>Perl\bin\perl.exe path\to\yourscript.pl
                then press enter and the windows will stay open.

                Comment

                • poolboi
                  New Member
                  • Jan 2008
                  • 170

                  #9
                  thanks for the help
                  ok
                  right now the error msg is i can't login with the username and password
                  i got no idea why
                  it isn't blocked by any firewalls
                  and when i telnet using the command prompt using the same password and username it is able to log into my telnet application
                  any idea why i can't log in when i use net::telnet??

                  Comment

                  • poolboi
                    New Member
                    • Jan 2008
                    • 170

                    #10
                    alright here's the warning message
                    i dunno if it helps

                    the warning mesage is

                    "global symbol $telnet3 requires explicit package name"

                    Comment

                    • KevinADC
                      Recognized Expert Specialist
                      • Jan 2007
                      • 4092

                      #11
                      instead of :

                      Code:
                      $telnet3 = 'foobar';
                      you need to declare it with "my":

                      Code:
                      my $telnet3 = 'foobar';
                      Thats what the error message you are getting means.

                      Comment

                      • poolboi
                        New Member
                        • Jan 2008
                        • 170

                        #12
                        OK
                        everything's fine but i guess the login has some problem
                        it alwayss time out at the login line
                        i read that i need to input some kind of prompt like bash
                        but i know that's for linux
                        does this prompt makes the differences on windows XP such that it can't read my login?
                        i really dunno why it's not logging in
                        pls help look into this? thank you

                        Comment

                        • numberwhun
                          Recognized Expert Moderator Specialist
                          • May 2007
                          • 3467

                          #13
                          Originally posted by poolboi
                          OK
                          everything's fine but i guess the login has some problem
                          it alwayss time out at the login line
                          i read that i need to input some kind of prompt like bash
                          but i know that's for linux
                          does this prompt makes the differences on windows XP such that it can't read my login?
                          i really dunno why it's not logging in
                          pls help look into this? thank you
                          My suggestion then, is to just do a telnet from the command line and see if it works. If not, then you need an account on that other machine. Also, make sure the other machine is allowing telnet as well.

                          Regards,

                          Jeff

                          Comment

                          • poolboi
                            New Member
                            • Jan 2008
                            • 170

                            #14
                            yup
                            it's allowing me to enter into the switch
                            i'm telnetting into a switch basically
                            from command line it can be done
                            how ever from the module net::telnet
                            i can't seem to log it in...i got no idea why

                            u might ask why i'm doing this rather from command line..
                            basically i'm creating a script to communicate one data base to another proprietary database
                            and the proprietary database can only be logged in by telnetting into the swtich
                            so the i still can't establishing a connection using net::telnet...
                            so any clues?
                            :)

                            Comment

                            • numberwhun
                              Recognized Expert Moderator Specialist
                              • May 2007
                              • 3467

                              #15
                              Originally posted by poolboi
                              yup
                              it's allowing me to enter into the switch
                              i'm telnetting into a switch basically
                              from command line it can be done
                              how ever from the module net::telnet
                              i can't seem to log it in...i got no idea why

                              u might ask why i'm doing this rather from command line..
                              basically i'm creating a script to communicate one data base to another proprietary database
                              and the proprietary database can only be logged in by telnetting into the swtich
                              so the i still can't establishing a connection using net::telnet...
                              so any clues?
                              :)
                              Not having done much of anything (at all) with this module, I am not sure why you aren't able to log in. I would re-read the module documentation and see if there is anything you may have missed.

                              Regards,

                              Jeff

                              Comment

                              Working...