def get(host, index):
index = int(index)
assert 1 <= index <= 4
tn = telnetlib.Telnet(host, 1234, 1)
tn.read_until(b"\r\n", 0.5)
tn.write(b"login admin admin\n")
tn.read_until(b"250 OK\r\n", 0.5)
tn.write("port {}\n".format(index).encode())
read = tn.read_until(b"\r\n", 0.5)
m = re.match(".*250 (\d).*", read.decode())
if m is None:
raise Exception("NetIO: could not match response")
value = m.group(1)
tn.write(b"quit\n")
tn.close()
return value == "1"
评论列表
文章目录