use strict; use Net::Telnet; # definitions my $testfilename = "iplist1.txt"; my $dumplog = "dumplog.txt"; my $outputlog = "outputlog.txt"; my $optionlog = "optionlog.txt"; my $inputlog ="inputlog.txt"; our $recordlog ="recordlog.txt"; my $string0 = 'Connected' ; my $string1 = "\015\012" ; my $string2 = '\\CR \\LF' ; # #open (OUT,'>>', "$recordlog"); # iterating file open (IPS, '<', $testfilename) or die('unable to open the file', $testfilename ); while (my $ip = ) { chomp $ip; my $telnett = Net::Telnet->new(Host => "$ip", Port => 'xxxx', Dump_log => "$dumplog", input_log => "$inputlog", option_log => "$optionlog", output_log => "$outputlog", timeout => 10, errmode => (sub { open(OUT, '>>', "$recordlog"); print OUT "Bad connection - Unable to connect to IP $ip at \r\n" ; print OUT "-------------------\r\n"; next;})); $telnett->open("$ip") or die "hai $telnett->errmsg "; # add Errmode and output handle print "connected \n"; $telnett->waitfor('//'); print "carriage return: sending \\CR \\LF \n"; print "carriage return: waiting ...\n"; my $output = $telnett->put(String => $string2, Errmode => 'die', Timeout => '4',); print "The server returned: $output \n"; # Error handling # my $etc0 # expanding IP Networks # my $etc1 # Logging everything # my $etc2 } #### 10.xx.yy.zzz 127.0.0.1 127.0.0.1 10.aa.bb.cc 10.aaa.bb.cc #### ad connection - Unable to connect to IP 10.xx.yy.zz at ------------------- Bad connection - Unable to connect to IP 10.xx.yy.zz at ------------------- Bad connection - Unable to connect to IP 10.xx.yy.zz at ------------------- #### # simple telnet_test use strict; use Net::Telnet; ### #my $testfilename = "telnet-tests.txt"; my $testfilename = "iplist1.txt"; my $dumplog = "dumplog.txt"; my $outputlog = "outputlog.txt"; my $inputlog="inputlog.txt"; my $logfilename = "./log/telnetlog${t}.txt"; our $testcount = 0; our $debug = 1; ### # instantiate a new telnet object my $telnet = Net::Telnet->new(Port => 'xxxx', Timeout => 10, Telnetmode => '0', Errmode => 'die', Prompt => '//', Dump_log => "$dumplog", output_log => "$outputlog", input_log => "$inputlog" ); my $string = "\015\012" ; #my $string = '\CR \LF' ; $telnet->open("10.aaa.bb.cc") or die "hai $telnet->errmsg "; print "connected \n"; $telnet->waitfor('//'); print "about to execute carriage return \n"; print "sending \\cr waiting ...\n"; my $output = $telnet->put(String => $string, Errmode => 'die', Timeout => '4',); print " $output \n"; #### root@xxxxx scripts]# perl test_telnet1.pl connected about to execute carriage return sending \cr waiting ... 1 #### root@xxxxx scripts]# cat dumplog.txt > 0x00000: 0d 0d 0a ... #### [root@xxxxx scripts]# telnet 10.aaa.bb.cc xxxx Trying 10.aaa.bb.cc... Connected to nodecc.dom.org.local (10.aaa.bb.cc). Escape character is '^]'. dds_pc: _ms=nodecc.dom.org.localþ_si=Process controllerþ_mid=9016þ_sev=0þ_dt=2010/07/29þ_tm=01:12:02þ_pkg=þ Connection closed by foreign host.