I want to set all the routers in our network(20 mikrotik routers).
So, I decide to use the telnet access with python programming language.
First, I have tested on a mikrotik router.
The below is my python script.
#!/usr/bin/python
import getpass
import sys
import telnetlib
import time
HOST='my-mikrotik-ip-address'
PORT='21'
user= raw_input("Enter your remote account: ")
password= getpass.getpass()
tn=telnetlib.Telnet(HOST,PORT)
tn.read_until("Login: ")
tn.write(user + "\n")
if password:
try:
tn.read_until("Password: ")
tn.write(password + "\n")
print tn.read_until('>')
tn.write("/ip add \n")
tn.read_until(">")
tn.write("\n")
tn.write(" print \n")
print tn.read_until('>')
time.sleep(10)
print tn.read_all()
tn.write("\n")
tn.read_until(">")
except EOFError, socket.error:
print time.strftime("%H:%M:%S "),
print "Telnet failure "
The result is not the one (“/ip address print”)
The result is below
MMM MMM KKK TTTTTTTTTTT KKK
MMMM MMMM KKK TTTTTTTTTTT KKK
MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK
MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK
MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK
MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK
MikroTik RouterOS 5.6 (c) 1999-2011 ttp://www.mikrotik.com/
[admin@[C]InC Solution] >
^[[?1;2c^[[60;3R
It doesn’t display the result for ‘/ip address print’
Is Anyone to help me? please, leave your comment.
Thanks for your reading.