Guest User

Untitled

a guest
Dec 14th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. def Connect(self, hostinfo, userinfo):
  2. self.client = paramiko.SSHClient()
  3. self.client.load_system_host_keys()
  4. self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  5. self.client.connect(hostinfo["ip"], hostinfo["port"], userinfo["username"], userinfo["password"])
  6. self.channel = self.client.invoke_shell()
  7. self.channel.settimeout(2)
  8.  
  9. def Send(self, cmd="", end=""):
  10. self.channel.send(''.join([cmd, 'n']))
  11. return self.Receive(end)
  12.  
  13. def Receive(self, end=""):
  14. re_ = re.compile(end)
  15. data = ""
  16. while True:
  17. temp = ""
  18. print(1111)
  19. # time.sleep(0.5)
  20. if self.channel.recv_ready():
  21. try:
  22. temp = self.channel.recv(65535).replace(b"rn", b"n").decode("GB18030")
  23. except socket.timeout:
  24. return data
  25. data = "".join([data, temp])
  26. if re_.search(data):
  27. return data
Add Comment
Please, Sign In to add comment