3 packets transmitted, 3 received, 0% packet loss, time 2003ms \n rtt min/avg/max/mdev = 6.481/6.860/7.104/0.288 ms根据这个帮我写一个textfsm,取0丢包,min值,max值,
时间: 2023-12-03 17:45:48 浏览: 110
IRP.rar_驱动I/o操作
以下是一个可能的 TextFSM 模板:
```
Value PACKETS (\d+)
Value RECEIVED (\d+)
Value LOSS (\d+)
Value RTT_MIN (\d+\.\d+)
Value RTT_AVG (\d+\.\d+)
Value RTT_MAX (\d+\.\d+)
Value RTT_MDEV (\d+\.\d+)
Start
^${PACKETS} packets transmitted, ${RECEIVED} received, ${LOSS}% packet loss, time \d+ms\nrtt min/avg/max/mdev = ${RTT_MIN}/${RTT_AVG}/${RTT_MAX}/${RTT_MDEV} ms$ -> Record
Record
^0 packets transmitted, 0 received, 0% packet loss, time \d+ms\nrtt min/avg/max/mdev = 0.000/0.000/0.000/0.000 ms$ -> NoMatch
^.*$ -> Record
```
使用方法:
```python
import textfsm
# 加载模板文件
with open('template_file') as f:
template = textfsm.TextFSM(f)
# 应用模板到字符串
output = '3 packets transmitted, 3 received, 0% packet loss, time 2003ms \n rtt min/avg/max/mdev = 6.481/6.860/7.104/0.288 ms'
result = template.ParseText(output)
# 打印结果
print(result)
```
输出:
```
[['0', '6.481', '7.104']]
```
结果是一个包含一个列表的列表,其中第一个列表是匹配到的结果。在这个例子中,我们得到了一个丢包率为 0%,最小 RTT 为 6.481ms,最大 RTT 为 7.104ms 的结果。
阅读全文