Commit 18c46fc4 authored by BaiJiangJie's avatar BaiJiangJie Committed by 老广

[Bugfix] 修复连接telnet资产失败,直接退出coco连接的bug (#164)

* [Bugfix] 修复连接telnet资产失败,直接退出coco连接bug

* [Update] 修复ssh/telnet连接失败信息格式展示
parent aabb9db5
......@@ -48,7 +48,7 @@ class SSHConnection:
if asset.domain:
sock = self.get_proxy_sock_v2(asset)
if not sock:
error = 'Connect gateway failed;'
error = 'Connect gateway failed.'
logger.error(error)
try:
......@@ -86,7 +86,8 @@ class SSHConnection:
system_user.username, asset.ip, asset.port,
password_short, key_fingerprint,
))
return None, None, error + '\n' + str(e)
error += '\r\n' + str(e) if error else str(e)
return None, None, error
return ssh, sock, None
def get_transport(self, asset, system_user):
......@@ -166,7 +167,12 @@ class TelnetConnection:
logger.debug('Get telnet server socket. {}'.format(self.client.user))
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(10)
self.sock.connect((self.asset.ip, self.asset.port))
try:
self.sock.connect((self.asset.ip, self.asset.port))
except Exception as e:
msg = 'Connect telnet server failed. \r\n{}'.format(e)
logger.error(msg)
return None, msg
# Send SGA and ECHO options to Telnet Server
self.sock.send(telnetlib.IAC + telnetlib.DO + telnetlib.SGA)
self.sock.send(telnetlib.IAC + telnetlib.DO + telnetlib.ECHO)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment