试图运行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跳,而这样做,通过我们的路由器,我得到更多的跳数任何建议为什么?
谢谢你的建议
这可能是由于超时的问题。试试。
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)