Guest User

Untitled

a guest
Dec 1st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. enter code here
  2.  
  3. #!/usr/bin/python
  4. #
  5. # Paramiko
  6. #
  7. import paramiko
  8. import sys
  9. import subprocess
  10. #
  11. # we instantiate a new object referencing paramiko's SSHClient class
  12. #
  13. vm=paramiko.SSHClient()
  14. vm.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  15. vm.connect('192.168.115.103',username='osmanl',password='xxxxxx')
  16. #
  17. vmtransport = vm.get_transport()
  18. dest_addr = ('192.168.115.103', 22)
  19. local_addr = ('127.0.0.1', 22)
  20. vmchannel = vmtransport.open_channel("direct-tcpip", dest_addr, local_addr)
  21. #
  22. jhost=paramiko.SSHClient()
  23. jhost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  24. jhost.load_host_keys('/home/osmanl/.ssh/known_hosts')
  25. jhost.connect('10.103.53.26', username='latiu', password='xxxx', sock=vmchannel)
  26. #
  27. stdin, stdout, stderr = rtr.exec_command("show version | no-more")
  28. #
  29. print stdout.readline()
  30. #
  31. jhost.close()
  32. vm.close()
  33. # End
  34.  
  35. $ python sshvm.py
  36. Traceback (most recent call last):
  37. File "sshvm.py", line 28, in <module>
  38. jhost.load_host_keys('/home/osmanl/.ssh/known_hosts')
  39. File "/usr/lib/python2.7/site-packages/paramiko-1.15.2-py2.7.egg/paramiko/client.py", line 121, in load_host_keys
  40. self._host_keys.load(filename)
  41. File "/usr/lib/python2.7/site-packages/paramiko-1.15.2-py2.7.egg/paramiko/hostkeys.py", line 94, in load
  42. with open(filename, 'r') as f:
  43. IOError: [Errno 2] No such file or directory: '/home/osmanl/.ssh/known_hosts'
  44.  
  45. #!/usr/bin/python
  46. #
  47. # Paramiko
  48. #
  49. import paramiko
  50. import sys
  51. import subprocess
  52. #
  53. # we instantiate a new object referencing paramiko's SSHClient class
  54. #
  55. vm=paramiko.SSHClient()
  56. vm.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  57. vm.connect('192.168.115.103',username='osmanl',password='xxxxxx')
  58. #
  59. vmtransport = vm.get_transport()
  60. dest_addr = ('10.103.53.26', 22) #edited#
  61. local_addr = ('192.168.115.103', 22) #edited#
  62. vmchannel = vmtransport.open_channel("direct-tcpip", dest_addr, local_addr)
  63. #
  64. jhost=paramiko.SSHClient()
  65. jhost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  66. #jhost.load_host_keys('/home/osmanl/.ssh/known_hosts') #disabled#
  67. jhost.connect('10.103.53.26', username='latiu', password='xxxx', sock=vmchannel)
  68. #
  69. stdin, stdout, stderr = jhost.exec_command("show version | no-more") #edited#
  70. #
  71. print stdout.read() #edited#
  72. #
  73. jhost.close()
  74. vm.close()
  75. # End
  76.  
  77. import paramiko
  78.  
  79. vm=paramiko.SSHClient()
  80. vm.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  81. vm.connect('192.168.92.163',username='user',password='cisco')
  82.  
  83. vmtransport = vm.get_transport()
  84. dest_addr = ('192.168.92.162', 22) #edited#
  85. local_addr = ('192.168.92.163', 1234) #edited#
  86. vmchannel = vmtransport.open_channel("direct-tcpip", dest_addr, local_addr)
  87.  
  88. jhost=paramiko.SSHClient()
  89. jhost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  90.  
  91. jhost.connect('192.168.92.162', username='cisco', password='cisco', sock=vmchannel)
  92.  
  93. stdin, stdout, stderr = jhost.exec_command("show version")
  94.  
  95. print (stdout.read()) #edited#
  96.  
  97. jhost.close()
  98. vm.close()
Add Comment
Please, Sign In to add comment