04-17-2020 07:12 AM
I was able to get device hostname with the following netmiko code.
>>> print(net_connect.find_prompt()) Cisco# >>> >>> print(net_connect.send_command('show running-config | include hostname')) hostname Cisco >>>
Would it be possible to remove `#` and `hostname` from the output?
Desired Output
>>> print(net_connect.find_prompt()) <= need to do something here Cisco >>> >>> print(net_connect.send_command('sh run | i host')) <= need to do something here Cisco >>>
Solved! Go to Solution.
04-17-2020 07:21 AM
Hi there,
Try the following:
>>> print(net_connect.find_prompt()[:-1]) >>> print(net_connect.send_command('sh run | i host').split()[1])
cheers,
Seb.
04-17-2020 07:21 AM
Hi there,
Try the following:
>>> print(net_connect.find_prompt()[:-1]) >>> print(net_connect.send_command('sh run | i host').split()[1])
cheers,
Seb.
04-17-2020 09:05 AM
Hi,
Instead of parsing the running-config (which means additional execution time for your script until the running-config is collected), why not getting the hostname directly using 'show hostname' command?
print(net_connect.send_command('show hostname'))
Cheers,
Sergiu
04-17-2020 05:48 PM
There is no "show hostname" on 3725
R1#show hostname ^ % Invalid input detected at '^' marker. R1# R1#show host? hosts R1#
03-19-2021 08:38 AM
I run 'show version | in uptime' which is way more faster than parsing running config.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide