Community discussions

MikroTik App
 
mmethw2003
just joined
Topic Author
Posts: 18
Joined: Wed Jan 05, 2011 6:33 am

Mikrotik With Perl Script

Wed Feb 20, 2013 10:55 am

Hi all ,

I have written a perl script to take a export from a Mikrotik router and write it to a file. Script works fine but the data that written is contain with garbage characters .. Is there any other way to prevent this???

#!/usr/bin/perl -w
use Net::Telnet;
use POSIX ;


$filepath = "/home/aaa";
#$hostname = "XXXXXXX"; #Router IP


sub MTRetrieve
{
my($uname, $pass, $hname, $prompt) = @_;
$telnet = new Net::Telnet (Timeout,5, Errmode=>'return');
$telnet->binmode(0);
$telnet->open($hname);
$telnet->login($uname,$pass);
$telnet->waitfor('/] >/i');
$msg = $telnet->errmsg;

print ("$msg\n");
$telnet->waitfor('/] >/i');
print "before export\n";
@expo = $telnet->cmd('/export');
print "after export\n";
# $telnet->waitfor('/] >/i');
return (@expo);
}


undef @RAWdata;
@RAWdata = MTRetrieve('username','paswrd','router ip');

print "before create File name\n";
$ffpath = $filepath."/"."test";
#chmod (0777, $ffpath) or die "Couldn't chmod $ffpath: $!";
open (MYFILE,">$ffpath");
print MYFILE @RAWdata;
close MYFILE;


====================================================================
Here I attached a part of what written in to the file

^M# feb/20/2013 14:04:40 by RouterOS 5.23
# software id = CZN9-VEKP
#
^[[m^[[36m/interface^[[m ^[[m^[[36methernet
^[[m^[[35mset^[[m 0 ^[[m^[[32marp^[[m^[[33m=^[[menabled ^[[m^[[32mauto-negotiation^[[m^[[33m=^[[m^[[32myes^[[m ^[[m^[[32mbandwidth^[[m^[[33m=^[[munlimited^[[m^[[33m/^[[munlimited ^[[m^[[34;1m\
^[[m^[[32mdisabled^[[m^[[33m=^[[m^[[32mno^[[m ^[[m^[[32mfull-duplex^[[m^[[33m=^[[m^[[32myes^[[m ^[[m^[[32ml2mtu^[[m^[[33m=^[[m1598 ^[[m^[[32mmac-address^[[m^[[33m=^[[mD4:CA:6D:2A:9E:9F ^[[m^[[34;1m\
^[[m^[[32mmaster-port^[[m^[[33m=^[[mnone ^[[m^[[32mmtu^[[m^[[33m=^[[m1500 ^[[m^[[32mname^[[m^[[33m=^[[mether6 ^[[m^[[32mspeed^[[m^[[33m=^[[m100Mbps
^[[m^[[35mset^[[m 1 ^[[m^[[32marp^[[m^[[33m=^[[menabled ^[[m^[[
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Mikrotik With Perl Script

Wed Feb 20, 2013 12:08 pm

what you see is colour coding used in console. you can use console options to turn it off while loggin in.

for exmaple: admin+c

for other console login options you can check wiki.mikrotik.com
 
mmethw2003
just joined
Topic Author
Posts: 18
Joined: Wed Jan 05, 2011 6:33 am

Re: Mikrotik With Perl Script

Wed Feb 20, 2013 1:10 pm

Hey It worked Like a Charm :) Thanks a Lot :)
what you see is colour coding used in console. you can use console options to turn it off while loggin in.

for exmaple: admin+c

for other console login options you can check wiki.mikrotik.com

Who is online

Users browsing this forum: No registered users and 13 guests