cisco traceroute的python脚本--看不到整个跳数。

问题描述 投票:0回答:1

试图运行python traceroute脚本trace卡住后5-7跳(不是30应该是).附上我的脚本。

#!/usr/bin/env python

from netmiko import ConnectHandler
from auto_encrypter_new import *

ios = {
        'device_type': 'cisco_ios',
        'ip': 'my_ip_device',
        'username': user_encrypt,
        'password': passwd_encrypt,
}

net_connect = ConnectHandler(**ios)
output = net_connect.send_command_timing('trace dest_ip')
print (output)

得到只有6跳,而这样做,通过我们的路由器,我得到更多的跳数任何建议为什么?

谢谢你的建议

cisco
1个回答
0
投票

这可能是由于超时的问题。试试。

output = net_connect.send_command_timing(f'trace {dest_ip}', delay_factor=4)

延迟因素已经解释过了 此处

如果还是不行,就试试

import time
from netmiko import ConnectHandler
from auto_encrypter_new import *

ios = {
        'device_type': 'cisco_ios',
        'ip': 'my_ip_device',
        'username': user_encrypt,
        'password': passwd_encrypt,
}

net_connect = ConnectHandler(**ios)
dest_ip = '8.8.8.8'


net_connect.write_channel(f'trace {dest_ip}')
time.sleep(10) # this is needed for the device to send a response. Test it and try to adjust timing if needed
output = net_connect.read_channel()
print(output)
© www.soinside.com 2019 - 2024. All rights reserved.