Guest User

Untitled

a guest
Apr 30th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import paramiko,socks
  2. import time
  3. import csv
  4. import getpass
  5. import fileinput
  6. import socket
  7.  
  8.  
  9.  
  10.  
  11. def enable_mode(SSH):
  12. # Enter privileged mode
  13. SSH.send("enn")
  14. time.sleep(1)
  15. SSH.send(ENABLE + "n")
  16. # Clear the buffer on screen
  17. output = SSH.recv(1000)
  18.  
  19. def disable_paging(SSH):
  20. # Disable Paging on Device
  21. SSH.send("term len 0n")
  22. time.sleep(1)
  23. # Clear buffer on the screen
  24. output = SSH.recv(1000)
  25.  
  26.  
  27. host, port = '10.179.220.11', 1080 #<-(Not sure ,if this host IP
  28. should be 127.0.0.1 or the actual jump box server IP)
  29.  
  30. # Set up your proxy information for this socket
  31. sock=socks.socksocket()
  32. sock.set_proxy(
  33. proxy_type=socks.SOCKS5,
  34. addr=host,
  35. port=port, # <- should this port be 22 or 1080?
  36.  
  37. )
  38.  
  39. # Connect the socket
  40. sock.connect((host, port))
  41.  
  42. # Create your Paramiko Transport
  43. transport = paramiko.Transport(sock)
  44. transport.connect(
  45. username='xyz', #<- should this be jump box username?
  46. password='ABC', #<- should this be jump box password?
  47. )
  48.  
  49.  
  50.  
  51. ssh_pre = paramiko.SSHClient()
  52. ssh_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  53. USERNAME = input("Please input your username:")
  54. PASSWORD = getpass.getpass("Please input password for" +" " + USERNAME +
  55. ":")
  56.  
  57. # Prompt user for enable password
  58. ENABLE = getpass.getpass("Please input the enable password:")
  59.  
  60. ssh_pre.connect('10.1.1.1', username = USERNAME, password = PASSWORD,
  61. sock=sock)
  62.  
  63.  
  64. # Use invoke_shell to establish an interactive session
  65. ssh = ssh_pre.invoke_shell()
  66.  
  67.  
  68. # Enable mode
  69. enable_mode(ssh)
  70.  
  71. # Turn off paging
  72. disable_paging(ssh)
  73.  
  74. ssh.send("show versionn")
  75. time.sleep(3)
  76.  
  77.  
  78. transport.close()
Add Comment
Please, Sign In to add comment