Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using netmiko module to connect H3C equipment (closed pit-- the division of H3C equipment)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Recently, it has been testing the paramiko and netmiko modules of network devices such as huawei and H4c through ssh protocol in Python. Why choose these two to find the answer on the Internet.

For examples of connecting network devices with paramiko modules and problems encountered, please refer to: https://blog.51cto.com/chier11/2116155

This paper only introduces the problem of using netmiko module to connect H3C network equipment and successfully close the pit: H4C split screen display.

Grumble: when netmiko connects to huawei devices, the split display function is automatically removed from the netmiko module, which means that all large amounts of information are displayed. For example: display interface brief, viewing information from more than 400 ports, the system will display split screens, but the command to cancel split display is set by default in netmiko's huawei module, as follows: screen-length 0 temporary (Huawei's command to cancel split display)

From _ _ future__ import print_functionfrom _ _ future__ import unicode_literalsimport timeimport refrom netmiko.cisco_base_connection import CiscoBaseConnectionfrom netmiko.ssh_exception import NetMikoAuthenticationExceptionfrom netmiko import logclass HuaweiBase (CiscoBaseConnection): def session_preparation (self): "Prepare the session after the connection has been established." Self._test_channel_read () self.set_base_prompt () self.disable_paging (command= "screen-length 0 temporary") # Clear the read buffer time.sleep (0.3 * self.global_delay_factor) self.clear_buffer () def config_mode (self, config_command= "system-view"): "" Enter configuration mode. "return super (HuaweiBase, self). Config_mode (config_command=config_command)

Here we probably guess why there is a command to cancel the split-screen display function in the connection of the netmiko module in the huawei, while the H3C equipment does not. After communicating with the manufacturers, it is found that the canceling split-screen display function of Huawei equipment can be set for users and is temporary. For example, after a user user logs in to a Huawei device and executes the command to cancel split-screen display, it has no effect on other users on the device (other users are still split-screen display). When a user user logs out of ssh, the split-screen display function of that user will be automatically restored, just like the definition: the environment for entering your home directory is as convenient and powerful. On the other hand, the split-screen display of H3C network devices is aimed at global devices, and it is not as temporary as entering and exiting the environment. So how to solve this kind of pit, after many times of online search and testing, and finally perfectly achieve a complete display of a large amount of information at one time.

If "- More -" in outp:

Outp + = conn1.send_command_timing (

'\ nfolk, strip_prompt=False, strip_command=False, normalize=False

) # # if you encounter more, enter more spaces. Normalize=False means not canceling the spaces before and after the command.

The code is as follows

From netmiko import ConnectHandlerfrom netmiko.ssh_exception import NetMikoTimeoutExceptionfrom netmiko.ssh_exception import NetMikoAuthenticationExceptiondef Get_CRC (): try: pynet1 = {'device_type': "hp_comware",' ip': "10.10.10.10", 'username': "CTyunuser",' password': "P@ssw0rd6900" } conn1 = ConnectHandler (* * pynet1) cmd='display counters inbound interface'# cmd='display interface brief\ n' outp=conn1.send_command_timing (cmd) if "- More -" in outp: outp + = conn1.send_command_timing ('\ n', strip_prompt=False, strip_command=False Normalize=False) * # encountered more Just enter a few more spaces, and normalize=False means not to cancel the spaces before and after the command *. Outp1 = outp.split ("\ n") print (outp1) except (EOFError,NetMikoTimeoutException): print ('Can not connect to Device') except (EOFError, NetMikoAuthenticationException): print (' username/password Wrongems') Except (ValueError, NetMikoAuthenticationException): print ('enable password bronzes') if _ _ name__== "_ _ main__": Get_CRC ()

The above is a summary of the differences in the use of the orders of Huawei and the three manufacturers in practice. If there is anything wrong, please correct it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report