Using Net::Telnet in Perl to connect to an adsl modem

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Net::Telnet in Perl to connect to an adsl modem
# 1  
Old 09-08-2009
Using Net::Telnet in Perl to connect to an adsl modem

First of all, congratulations on this forum! Very mice material!
This is my fist thread and it has to do with connecting to an adsl modem and executing some commands.

Heres what I do:

$username = 'admin';
    $passwd = 'admin';
    $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'return',input_log=>'input.txt', Port=> "8081" );
    $telnet->open(Host => $ip_number) || print " connection refused.\n";
    $telnet->waitfor("/User\ Name\ :");
    $telnet->waitfor("/User\ Password\ :");
    $telnet->waitfor("CONF\ :\>");
    $telnet->print('monitor adsl history');
    $telnet->waitfor("CONF\ :\>");
    $telnet->print('monitor ppp');
    $telnet->waitfor("CONF\ :\>");
    $telnet->waitfor("USER\ :\>");
    $telnet->waitfor("Do\ you\ want\ to\ disconnect\(y\/n\)\ \?\ \ :");

But it does not work. Nothing gets printed on input.txt file.
My guess is that something goes wrong with the waitfor() subs as the connection hungs-up after exiting, as I cannot connect again.
Below is a copy-paste of the output when doing it manually.
Thanks in advance!


[portal@noc-5 ~]$ telnet ***.***.***.*** 8081
Trying ***.***.***.***...
Connected to ***.***.***.***.
Escape character is '^]'.
User Name : admin
User Password : *****

 Telnet Manager Version 1.21.1S-O

Type ? for Command-Sensitive Help, TAB match command

CONF :> monitor adsl history

(1) ADSL Run-time Information:

 <ADSL History>
      Date Time         Data Rate(Up/Dw)  Noise Margin(U/D) Attenuation(U/D)
 --------------------- ------------------ ----------------- ----------------
 [09/08/2009 17:13:30]  1023/20476 Kbps        13/16 dB          0/ 3 dB
 [09/08/2009 17:18:30]  1023/20476 Kbps        13/16 dB          0/ 3 dB

CONF :> monitor ppp

 <PPP Session Status>
 No       Date Time       Status  Reason
 -- --------------------- ------ ----------------------------------------
  1 [08/01/2003 00:02:08]    Up  If(PPPoE1) PPP connection ok !

 <PPP Failure History>
 There is no failure log.

CONF :> exit

USER :> exit

Do you want to disconnect(y/n) ?  : y

 Disconnect by user.....Connection closed by foreign host.

Last edited by Ravendark; 09-08-2009 at 12:31 PM..
# 2  
Old 09-08-2009
I think you are suppose to tell it a prompt type (e.g. bash). Try using to dump_log(), instead of input_log(), for debugging purposes anyways.

This may shed some more light on the subject if you haven't read it all ready that is:

Net::Telnet -
# 3  
Old 09-08-2009
If I have understood correctly, defining a prompt is the same thing as using the waitfor() sub
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ENTER for modem configuration via telnet

Hiya, I'm trying to write a shell script to enter a bunch of loooooong configuration commands (to set ip, gateway etc.) for a quite outdated modem. It must be accessed via telnet. Here the preliminary code: #!/bin/bash (echo "open"; sleep 10 echo "Administrator";... (1 Reply)
Discussion started by: mrsbellamy
1 Replies

2. Shell Programming and Scripting

Perl variables inside Net::Telnet::Cisco Module doesn't work

I am writing perl script to configure Cisco device but Variables inside Net::Telnet::Cisco Module doesn't work and passed to device without resolving. Please advise. here is a sample of script: use Net::Telnet::Cisco; $device = ""; ($o1, $o2, $o3, $o4) = split(/\./,$device);... (5 Replies)
Discussion started by: ahmed_zaher
5 Replies

3. Shell Programming and Scripting

Pressing "Enter/Space bar" using Net::TELNET? in Perl

I'm trying to learn how to get my script to execute the enter button when it telnets into a router and the router displays output but you need to press the space bar or enter button to continue displaying my output of the router. How is this done? (0 Replies)
Discussion started by: xmaverick
0 Replies

4. Shell Programming and Scripting

Need help on use of "cmd" command in net::Telnet module in PERL

in "cmd" command i want to copy the ouput of the command excuted to a particular file in a directory. How to do this..?? Ex : $telnet->cmd(String => 'allip:acl=a1;',Prompt => '/</'); i want to copy o/p of the command "allip:acl=a1;" in a log file in a particular directory. Plz suggest.. (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

5. Windows & DOS: Issues & Discussions

Need Help on "waitfor" command in net::Telnet Module in PERL

Hi, Can anybody help me in writing command "waitfor" for string "C:\WINNT\Profiles\mfcf0508>" while using net::Telnet module. I tried the below format : $telnet->waitfor('/"C\:\WINNT\Profiles\mfcf0508>".*$/i'); Getting error as : pattern match timed-out Plz help me (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

6. Solaris

Installing USB adsl modem?

Hello all, granted that I am an absolute beginner with Solaris, I'd like to use my adsl modem, t's a Zyxel prestige 630. I managed to install and configure it under Ubuntu using the drivers from Conexant AccessRunner ADSL USB modems with Linux ; is there a chance to do the same under Solaris 10... (0 Replies)
Discussion started by: clalfa
0 Replies

7. UNIX for Dummies Questions & Answers

cannot connect net in rhl9

I installed rhl 9 in my system but the problem is i cannot connect my net to it any help please (2 Replies)
Discussion started by: shafique
2 Replies

8. Solaris

Solaris 10 ADSL USB modem problem

Hi, I have USB Siemens Santis 100 ADSL modem.I need driver for this modem on Solaris 10.Please help me with some info.Platform is x86.Thanks. (2 Replies)
Discussion started by: Upravnik
2 Replies

9. UNIX for Dummies Questions & Answers

Got connected with Modem but cannot dial Telephone no. to connect to host

Hello There, I configure my Modem as follow. Step1. # admintool & Then from Browse --> Serial Port i select tta port and Edit --> Modify From that i select Template : Modem:Dial Out Baud Rate: 9600 Ok Step 2 # tip /dev/cua/a connected (1 Reply)
Discussion started by: abidmalik
1 Replies
Login or Register to Ask a Question