Telnet клинет на Python
Задача: получить уровни сигнала на железке OLT
Решение:
#!/usr/bin/env python2
#encoding: UTF-8
import getpass
import sys
import telnetlib
HOST = "33.22.57.11"
user = "admin";
password = "sergsdrtg"
def teln(num):
tn = telnetlib.Telnet(HOST)
tn.set_debuglevel(0)
tn.read_until("Username:")
tn.write(user + "\r")
tn.read_until("word:")
tn.write(password + "\r")
tn.write("show olt "+str(num)+" optical-online-onu\r ")
tn.read_until("epon#")
tn.write("logout\r")
print tn.read_all()
tn.close()
teln(1)
teln(2)
teln(3)
teln(4)