如何telnet expect ascii character cli python 2.7

2024-10-02 10:26:39 发布

您现在位置:Python中文网/ 问答频道 /正文

python telnet连接

发送{msg}

接收消息日志

1 : ^[]0;ABCD - ABCD - file=/tmp/1234^GConnected to 123.123.123.123 (test=test_ROOT_MO,Context=ABCD,ManagedElement=ABCD)^M
2 : ^M
3 : Last MO: 11668. Loaded 11668 . Total: 11669 MOs.^M
4 : ^M

5 : ^[[1;32mABCD^[[0m>

此消息(^[[1;32mABCD^[[0m>;)日志 ,但telnet conn和send msg

    ABCD> msg
    ABCD - ABCD - file=/tmp/1234^GConnected to 123.123.123.123 (test=test_ROOT_MO,Context=ABCD,ManagedElement=ABCD)
    Last MO: 11668. Loaded 11668 . Total: 11669 MOs.   

    *ABCD>*

上一个>;颜色饱满(绿色)

问)。我要找到“^[[1;32mABCD^[[0m>;”(ABCD总是变化的)

我在代码下尝试,但失败了

--->;self.teln.read\u直到('\^[.\^[>;*',300个)


Tags: totestgtcontextmsgroottmptelnet
1条回答
网友
1楼 · 发布于 2024-10-02 10:26:39

对于Tcl expect,我建议:

I assume you're trying to match the prompt, and the colour codes are messing you up. I'd keep it as simple as possible: match the angle bracket and space at the end of input:
expect -re {> $}

对于python的telnetlib,似乎read_until不能与正则表达式一起工作。我想知道这是否足够:

self.teln.read_until('[0m> ', 300)

也许你想要read_eager()或者read_very_eager()

相关问题 更多 >

    热门问题