本文整理汇总了Python中telnetlib.Telnet.set_debuglevel方法的典型用法代码示例。如果您正苦于以下问题:Python Telnet.set_debuglevel方法的具体用法?Python Telnet.set_debuglevel怎么用?Python Telnet.set_debuglevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telnetlib.Telnet
的用法示例。
在下文中一共展示了Telnet.set_debuglevel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import set_debuglevel [as 别名]
from datetime import datetime
line = ["ACP_1344_352", "ACP_2688_512", "ACP_4032_512", "ACP_5120_512", "ACP_5344_512", "ACP_6144_512", "ACP_7168_512", "ACP_8168_512"]
down = [1344, 2688, 4032, 5120, 5344, 6144, 7168, 7168]
up = [352, 512, 512, 512, 512, 512, 512, 512]
if __name__ == "__main__":
f = open("ip.txt", "r")
for l in f.readlines():
l = l[0:len(l)-1]
print l
try:
t1 = 10
t2 = 5
tn = Telnet(l, 23, t1)
tn.set_debuglevel(0)
print tn.read_until(":", t2)
tn.read_until("\xff\xfc\x03", 1)
tn.write("root\n")
print tn.read_until(":", t2)
tn.write("mduadmin\n")
print tn.read_until(":", t2)
tn.write("y")
print tn.read_until(">", t2)
tn.write("enable\n")
print tn.read_until("#", t2)
tn.write("time %s\n" % datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print tn.read_until("#", 1)
tn.write("save\n")
print tn.read_until(":", t2)
tn.write("\n")
示例2: __enter__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import set_debuglevel [as 别名]
class Remote:
def __enter__(self):
self.t = Telnet(HOST)
self.t.set_option_negotiation_callback(process_option)
self.t.set_debuglevel(DEBUG_LEVEL)
return self
def __exit__(self, type, value, traceback):
self.t.close()
return False
def is_on(self):
self.t.write("?P\r\n")
state = self.t.expect(["PWR1", "PWR0"], 0.2)
return state[2] == "PWR0"
def off(self):
self.t.write("PF\r\n")
# neet to set "network standby" to on in the receiver settings
# otherwise, this won't work
def on(self):
self.t.write("PO\r\n")
time.sleep(0.2)
self.t.write("PO\r\n")
# defining the actions to take
# between volume(-30) and volume(-40) is normally comfortable
def volume(self, negDezibel):
vol = negDezibel * 2 + 161
self.t.write("%03dVL\r\n" % vol)
def get_volume(self):
try:
self.t.write("?V\r\n")
match = self.t.expect(["VOL\d\d\d"], 0.2)
if match[0] == 0: # got valid volume
return (int(match[2].strip()[3:]) - 161) / 2
except:
pass
return -100
def get_device(self):
try:
self.t.write("?F\r\n")
match = self.t.expect(["FN\d\d"], 0.2)
if match[0] == 0: # valid device
return {
'FN02': "tuner",
"FN04": "PC",
"FN10": "TV",
"FN01": "AUX",
"FN25": "Pi"
}.get(match[2].strip(), "unknown")
except:
pass
return "n/a"
def select_tuner(self):
self.t.write("02FN\r\n")
def select_pc(self):
self.t.write("04FN\r\n")
def select_tv(self):
self.t.write("10FN\r\n")
def select_pi(self):
self.t.write("25FN\r\n")
def select_aux(self):
self.t.write("01FN\r\n")
def mute(self, should_mute):
if should_mute:
self.t.write("MO\r\n")
else:
self.t.write("MF\r\n")