原文链接:https://www.jianshu.com/p/38c254e61722
作者: shark
一、安装
pip3 install Exscript
二、使用
In [127]: from Exscript.util.interact import read_login
In [128]: from Exscript.protocols import SSH2
In [129]: account = read_login()
Please enter your user name [shark]: admin
Please enter your password:
In [130]: conn = SSH2()
In [131]: conn.connect('192.168.2.100')
Out[131]: True
In [132]: conn.login(account)
In [133]: conn.execute("show ip interface br")
Out[133]: (0, <_sre.SRE_Match object; span=(146, 150), match='\nR1#'>)
In [134]: conn.response
Out[134]: 'show ip interface br\r\nInterface IP-Address OK? Method Status Protocol\r\nFastEthernet0/0 192.168.2.100 YES manual up up \r'
In [135]: conn.execute("show ip interface br")
Out[135]: (0, <_sre.SRE_Match object; span=(146, 150), match='\nR1#'>)
In [136]: conn.response
Out[136]: 'show ip interface br\r\nInterface IP-Address OK? Method Status Protocol\r\nFastEthernet0/0 192.168.2.100 YES manual up up \r'
In [137]: conn.execute("show ip interface br")
Out[137]: (0, <_sre.SRE_Match object; span=(146, 150), match='\nR1#'>)
In [138]: conn.execute("show ip interface br")
Out[138]: (0, <_sre.SRE_Match object; span=(146, 150), match='\nR1#'>)
In [139]: conn.response
Out[139]: 'show ip interface br\r\nInterface IP-Address OK? Method Status Protocol\r\nFastEthernet0/0 192.168.2.100 YES manual up up \r'
In [140]: conn.send('exit\r')
In [141]: conn.close()
网友评论