netio_kshell.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:labgrid 作者: labgrid-project 项目源码 文件源码
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"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号